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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moroccanplaya
    New Member
    • Jan 2011
    • 80

    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
    Code:
    puts("please give your archive a name and a path:\n");
    			scanf("%s", archive_name);
           
    if( create_pointer = fopen(archive_name, "r") != NULL)
    //code//
  • mac11
    Contributor
    • Apr 2007
    • 256

    #2
    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>?

    Comment

    • moroccanplaya
      New Member
      • Jan 2011
      • 80

      #3
      i did use stdio.h heres more of the code

      Code:
      #include<stdio.h>
      #include<stdlib.h>
      #include<fcntl.h>
      #include<string.h>
      #define QUIT 5 
      
      
      int get_menu_choice ( void ); 
      
      int main()
      {
        
      
          //buffer for the text/bianry to be stored//
          unsigned char buffer[10000];
          // to store the number of charachters to read/write "for fread/fwrite//
          int n;
          //char to stor the user input for system output// 
          char input[4] = "ls"; 
          //int to store the user chocie// 
          int choice = 0 ;
          
      	//name of new archive is held// 
          char archive_name[256];  
          //name of the original file is held// 
          char original_file[256];
          //name of archive is held//
          char archive[256];
          //name of archive that is going to be extracted is held// 
          char xarchive[256];
          //name of the file that is extracted is held// 
          char extracted[256];
          
          //points to the original file thats is to be copied//
          FILE *original_pointer = NULL;
          //points to the copied file//
          FILE *copy_pointer = NULL;
          //points to created  archive//
          FILE *create_pointer = NULL;
          //points to the open file// 
          FILE *open_pointer = NULL;  
          //points to the stored archive// 
          FILE *archive_pointer = NULL;
          //points to the extracted file// 
          FILE *copy = NULL;
          //points to the open extracted file// 
          FILE *open_xtractcp =NULL;
          //points to the archive thats about to be extracted//
          FILE *xtract = NULL ;
          
          
       
          
      
          
          
      			while (choice != QUIT )
         	    {
              	choice = get_menu_choice();
              
              	if (choice == 1)
              {
            		while(1)
              { 
      			puts("please give your archive a name and a path:\n");
      			scanf("%s", archive_name);
             
              	if( create_pointer = fopen(archive_name, "r") != NULL)
              {
              	printf("file already exists\n");
              	fclose(create_pointer);
              	continue;
              }

      Comment

      • moroccanplaya
        New Member
        • Jan 2011
        • 80

        #4
        i have an warning: assignment makes pointer from integer without a cast on line 68

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          Its an order-of-operations problem.
          Code:
          if( create_pointer = fopen(archive_name, "r") != NULL)
          is equivalent to
          Code:
          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
          Code:
          if( (create_pointer = fopen(archive_name, "r")) != NULL)
          You need to add that additional pair of parentheses to override the natural order of operations.

          Comment

          • moroccanplaya
            New Member
            • Jan 2011
            • 80

            #6
            thanks i would never of picked that up much appreciated, i got to keep that in mind

            Comment

            Working...