0

I have an issue with the following code.

int main (int argc, const char * argv[]) { #define MAXCHARACTERS 10 #define MAXNUMBERS 2 char buffer[MAXCHARACTERS]; numberOfStructs = 0; allocSize = 10; array = malloc(allocSize * sizeof(StructItem)); dataLink *link; do { Album *tempStruct; fgets(&(*tempStruct->firstField),MAXCHARACTERS, stdin); fgets(&(*tempStruct->secondField), MAXCHARACTERS, stdin); fgets(buffer, MAXNUMBERS, stdin); sscanf(buffer, "%d", &(tempStruct->thirdField) == 1); // line 26 link = List(&tempStruct); array[numberOfStructs] = (*tempStructs); numberOfStructs += 1; array = reAllocArray(&array, &allocSize, numberOfstructs); } while(link->newStruct != NULL); printList(&array, numberOfStructs); freeArray(&array, numberOfStructs); } 

I get warnings as follows

/main.c:26: warning: comparison between pointer and integer warning: passing argument 1 of 'List' from incompatible pointer type

I get a few of the "passing argument 1" error messages.

What am I doing wrong with these pointers?

Thanks

1
  • 2
    What is the type of Album? Or rather, how have you defined that type? Commented Feb 13, 2011 at 8:50

4 Answers 4

2

It seems to me that you are misusing sscanf, the third parameter you are passing to it is the logical result from a comparison between an address and the number 1. What are you trying to accomplish there?

Sign up to request clarification or add additional context in comments.

Comments

1
Album *tempStruct; fgets(&(*tempStruct->firstField),MAXCHARACTERS, stdin); 

tempStruct is just a pointer and you should not store anything on this pointer offset

&(*tempStruct->firstField) // or just tempStruct->firstField since &* is just cancellation 

I am not sure how this code works but from my knowledge i can see that each line using tempStruct is access violation without exception at

link = List(&tempStruct); 

and

&(tempStruct->thirdField) == 1 

Will be most likley FALSE in all cases since it is just pointer which can be 1 just by accident.

Comments

0

You are missing multiple type definitions.

For example, numberOfStructs = 0; should be int numberOfStructs = 0; The same applies to allocSize, array, and datalink.

If you only posted snippets of your code and your original code does not have those problems, then please let us know which line of code causing the error. The line numbers are likely incorrect.

1 Comment

I have them in a header file.
0

Probably you just copied code that also does test the return of scanf against 1? Then you have gotten your () wrong. And effectively you should put that into an if clause and test for success.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.