473,508 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Warning]assignment makes integer from pointer without a cast

4 New Member
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
1 3545
donbock
2,426 Recognized Expert Top Contributor
  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

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

Similar topics

6
95798
by: Jason | last post by:
I have a function (Inet_ntop) that returns const char * and if I try to assign that return value to a char * variable, I get the gcc error message: warning: assignment discards qualifiers from...
14
4049
by: Markus Dehmann | last post by:
The following if condition if((stream = fmemopen((void*)str, strlen(str), "r")) == NULL){ // ... } gives me a warning: assignment makes pointer from integer without a cast But only when I...
4
36157
by: Dawn Minnis | last post by:
Hi When I compile my files I get the following: driver.c: In function `main': driver.c:49: warning: assignment makes integer from pointer without a cast driver.c:50: warning: assignment...
10
9469
drhowarddrfine
by: drhowarddrfine | last post by:
warning: assignment makes pointer from integer without a cast I get that when I compile a C file where the function is defined as this: char **getvars() and the calling function has this...
1
3751
by: woods1313drew | last post by:
The following code in c+ gives me the warning assignment makes integer from pointer without a cast. destination is set as char destination to limit the input string to 10 characters. name is an...
3
16570
by: nexusdarkblue | last post by:
Hello everyone, I am somewhat new to C programming (I started last year) and I'm fairly good at it so far...that is, until I've recently started working with structures. In my current program,...
5
6044
by: plazzasele | last post by:
I want to register a new Person by using the set and get method. I am running my code on a program ( DEVc++), and when i compile the code i get this error message: assignment from incompatible...
6
4498
by: suvas | last post by:
I have C code. On compliation it shows error, warning: assignment from incompatible pointer type Actually I wanted to evaluate integral then sum all the integrals. I would be glad if anyone could...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.