473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do you make sure you have the right pointer type?

i get this message when compiled
warning: assignment makes pointer from integer without a cast
Expand|Select|Wrap|Line Numbers
  1. puts("please give your archive a name and a path:\n");
  2.             scanf("%s", archive_name);
  3.  
  4. if( create_pointer = fopen(archive_name, "r") != NULL)
  5. //code// 
  6.  
  7.  
Jan 12 '11 #1

✓ answered by donbock

Its an order-of-operations problem.
Expand|Select|Wrap|Line Numbers
  1. if( create_pointer = fopen(archive_name, "r") != NULL) 
is equivalent to
Expand|Select|Wrap|Line Numbers
  1. if( create_pointer = (fopen(archive_name, "r") != NULL)) 
That is create_pointer is assigned the integer value 1 (true) or 0 (false).
What you want is
Expand|Select|Wrap|Line Numbers
  1. if( (create_pointer = fopen(archive_name, "r")) != NULL)
You need to add that additional pair of parentheses to override the natural order of operations.

5 1344
mac11
256 100+
There's not enough code in your example for me to see what the exact issue is, but I'd suspect that maybe you didn't #include <stdio.h>?
Jan 12 '11 #2
i did use stdio.h heres more of the code

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<fcntl.h>
  4. #include<string.h>
  5. #define QUIT 5 
  6.  
  7.  
  8. int get_menu_choice ( void ); 
  9.  
  10. int main()
  11. {
  12.  
  13.  
  14.     //buffer for the text/bianry to be stored//
  15.     unsigned char buffer[10000];
  16.     // to store the number of charachters to read/write "for fread/fwrite//
  17.     int n;
  18.     //char to stor the user input for system output// 
  19.     char input[4] = "ls"; 
  20.     //int to store the user chocie// 
  21.     int choice = 0 ;
  22.  
  23.     //name of new archive is held// 
  24.     char archive_name[256];  
  25.     //name of the original file is held// 
  26.     char original_file[256];
  27.     //name of archive is held//
  28.     char archive[256];
  29.     //name of archive that is going to be extracted is held// 
  30.     char xarchive[256];
  31.     //name of the file that is extracted is held// 
  32.     char extracted[256];
  33.  
  34.     //points to the original file thats is to be copied//
  35.     FILE *original_pointer = NULL;
  36.     //points to the copied file//
  37.     FILE *copy_pointer = NULL;
  38.     //points to created  archive//
  39.     FILE *create_pointer = NULL;
  40.     //points to the open file// 
  41.     FILE *open_pointer = NULL;  
  42.     //points to the stored archive// 
  43.     FILE *archive_pointer = NULL;
  44.     //points to the extracted file// 
  45.     FILE *copy = NULL;
  46.     //points to the open extracted file// 
  47.     FILE *open_xtractcp =NULL;
  48.     //points to the archive thats about to be extracted//
  49.     FILE *xtract = NULL ;
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.             while (choice != QUIT )
  58.            {
  59.             choice = get_menu_choice();
  60.  
  61.             if (choice == 1)
  62.         {
  63.               while(1)
  64.         { 
  65.             puts("please give your archive a name and a path:\n");
  66.             scanf("%s", archive_name);
  67.  
  68.             if( create_pointer = fopen(archive_name, "r") != NULL)
  69.         {
  70.             printf("file already exists\n");
  71.             fclose(create_pointer);
  72.             continue;
  73.         }
  74.  
  75.  
  76.  
  77.  
  78.  
Jan 12 '11 #3
i have an warning: assignment makes pointer from integer without a cast on line 68
Jan 12 '11 #4
donbock
2,426 Expert 2GB
Its an order-of-operations problem.
Expand|Select|Wrap|Line Numbers
  1. if( create_pointer = fopen(archive_name, "r") != NULL) 
is equivalent to
Expand|Select|Wrap|Line Numbers
  1. if( create_pointer = (fopen(archive_name, "r") != NULL)) 
That is create_pointer is assigned the integer value 1 (true) or 0 (false).
What you want is
Expand|Select|Wrap|Line Numbers
  1. if( (create_pointer = fopen(archive_name, "r")) != NULL)
You need to add that additional pair of parentheses to override the natural order of operations.
Jan 12 '11 #5
thanks i would never of picked that up much appreciated, i got to keep that in mind
Jan 12 '11 #6

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

Similar topics

3
by: Brian Stubblefield | last post by:
Dear clc members, I am rather new to the C programming language. I have a rather large program that I am currently debugging. Currently, the following snippet of code in the c program: ...
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
6
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it...
8
by: Michael | last post by:
Hi all, why do I get a message: warning: passing arg 1 of `collectInput' from incompatible pointer type In 'main' have: char inputString; collectInput(&inputString);
1
by: wanglei0214 | last post by:
I compiles a program in SLOS, but there is a warning i donot know how to remove? here is the framework of the code: typedef struct device_tree { ...... union {
3
by: Frederick Gotham | last post by:
For objects, we have "void*" as the generic pointer type. For instance: enum ParamType { Int, Double }; void Func(void *const p,ParamType const pt) { switch (pt) { case Int: *(int*)p = 42;...
15
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
9
by: cheesiong | last post by:
Can anyone explain the following codes? especially the cast of pointer type. What does it really mean. Thanks. float f1; unsigned long l1; f1=4.5; l1=*(unsigned long*)&f1;
1
by: iammilind | last post by:
Is there any way to change a pointer type to our user defined type. For example, In my code, I have something like this: ================================= int i = 0; int *p; int **pp;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.