I'm having problems with my code all over. I have to be able to open a command line argument( which i know how to do). create a linked list, and print it backwards. This is what i have but im stuck with errors that i don't know how to fix. I don't have any errors in the insertNode function just main and printList. basically if the file i open is "ABC" , I need to print "CBA"

header file:

#include <stdio.h>
#define my

typedef char KEY_TYPE;
typedef struct
{
KEY_TYPE key;
} DATA;

typedef struct nodeTag
{ DATA data;
struct nodeTag* link;
} NODE;

Main:

#include "my.h"
#include <stdio.h>

int main(int argc, char *argv[])
{
NODE* pList;
FILE* p;
pList = NULL; NODE* pPre = NULL; DATA item; int y;
p = fopen(argv[1],"r");
while(y = fscanf(p, %c, &(item.key))!EOF);
{
pList = insertNode(pList,pPre,item);
}
countVowels (NODE* pList);
countChars (NODE* pList);
return 0;
}

PRINTLIST FUNCTION:

#include "my.h"
#include <stdio.h>
void printList (NODE* pList)
{
NODE* pWalker;
pWalker = pList;
printf("The linked list is ");

while(pWalker)
{
printf("%3c", pWalker.data.key);
pWalker = pWalker->link;
}
printf("\n");
return;
}

these are basically errors i keep getting:
main.c:11: error: syntax error before '%' token
main.c:13: warning: assignment makes pointer from integer without a cast
printlist.c: In function `printList':
printlist.c:11: error: request for member `data' in something not a structure or union

Recommended Answers

All 6 Replies

I can help you with two errors.

FIRST

main.c:11: error: syntax error before '%' token

When you use fscanf the format must be as a string of characters: between quotes.

while(y = fscanf(p, %c, &(item.key))!EOF);

SECOND

printlist.c:11: error: request for member `data' in something not a structure or union

If you want to call a member from a pointer of your structure you have to use '->' instead of a '.' when you call "data":

printf("%3c", pWalker->data.key);//>>> pWalker->data.key <<<<

thanks a lot!! I figured out the -> one but the first one helped greatly! any idea about the cast warning?

I can help you with two errors.

FIRST

When you use fscanf the format must be as a string of characters: between quotes.

while(y = fscanf(p, %c, &(item.key))!EOF);

I'm not sure what you mean by your help.. like this?

while(y = fscanf(p,"%c", &(item.key))!EOF);

-when I do it this way it says error before !

nevermind You helped tremendously! now i just need to figure out why im getting
main.c:13: warning: assignment makes pointer from integer without a cast

I think this problem is in the function insertNode. The parameters of this function aren't the same of the ones you are using or the return value isn't a pointer. There are many posible errors.

check your code again!

No clue why im getting the cast warning...

#include "my.h"

NODE* insertNode(NODE* pList, NODE* pPre, DATA item)
{
    NODE* pNew;

    if(!(pNew = (NODE*)malloc(sizeof(NODE))))
        printf("\aMemory overflow in insert\n");
            exit (100);
    pNew->data = item;
    if (pPre == NULL)
    {
        pNew->link = pList;
        pList = pNew;
    }
    else
    {
        pNew->link = pPre->link;
        pPre->link = pNew;
    }
    return pList;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.