By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

[Warning]assignment makes integer from pointer without a cast

P: 4
The title is the warning I get when I try to run the following function

Expand|Select|Wrap|Line Numbers
  1. char * setup_mutations()
  2. {
  3.     char *result = malloc(sizeof(char));
  4.     int i;
  5.     char c, current, string[MAX_STRING];
  6.     FILE * fp;
  7.  
  8.     if((fp = fopen("mutations.txt","r"))==NULL){
  9.         printf("Mutations file not available\n");
  10.         exit(2);
  11.     }
  12.  
  13.     for(i=0; i<256; i++){
  14.         //result[i] = malloc(sizeof(char));
  15.         result[i] = '\0';
  16.     }
  17.  
  18.     while ( (c = fgetc(fp) ) != EOF ){
  19.         current = c;
  20.  
  21.         for(c=fgetc(fp); c!=' '; c=fgetc(fp)){
  22.  
  23.         }
  24.  
  25.         i=0;
  26.  
  27.         for(c=c; c!='\n'; c=fgetc(fp)){
  28.             string[i] = c;
  29.             i++;
  30.         }
  31.         i = current;
  32.         result[i] = string;
  33.     }
  34.  
  35.     if((fclose(fp))==-1)printf("Mutations file didn't close properly\n");
  36.     return result;
  37. };
It comes from the line 32. Any help that helps me fix this problem and understand why it has arisen is appreciated.

Thanks
Dec 7 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,400
  1. Line 3 establishes result as a pointer to a single char; however line 15 seems to think that result points to 256 chars. It doesn't.
  2. Lines 21 and 27. Consider what happens if fgetc returns EOF.
  3. Line 21. It is customary for no-body for loop to have a single bare semicolon as the body.
  4. Line 28. How do you know you won't write past the end of string?
  5. Line 32. result is a pointer to a single char; thus result[i] is a char. This line tries to store a pointer-to-char there. That's why you get that warning.
Dec 8 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.