473,569 Members | 2,872 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 3553
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
95811
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 pointer target type Does anyone know what this warning means? Why do I get it? The program compiles and appears to work, but I'd like to understand...
14
4055
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 compile it with gcc. With g++ it's fine. Why does the warning show up and how can I get rid of it (using gcc)?
4
36168
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 makes integer from pointer without a cast driver.c:51: warning: assignment makes integer from pointer without a
10
9479
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 declared: char **s; and I write: s=getvars();
1
3758
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 array of ten places char name iv looked in several books but cant find an references to integer pointer errors. Could someone tell me what i am doing...
3
16573
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, I'm simply trying to initialize a simple array of structures that will be the test template for other similar programs I plan on using in the future. ...
5
6046
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 pointer type. #include <stdlib.h> #include <stdio.h> struct Person { char *name;
6
4505
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 help me. Thanks #include <stdlib.h> #include <stdio.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_math.h> #include <gsl/gsl_vector.h>...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.