please help

This is a discussion on please help within the C Programming forums, part of the General Programming Boards category; Thanks man. I get the following errors: ass.c: In function `open_batch': ass.c:112: warning: assignment makes pointer from integer without a ...

  1. #1
    ck1
    ck1 is offline
    Registered User
    Join Date
    Mar 2005
    Posts
    9

    please help

    Thanks man. I get the following errors:
    ass.c: In function `open_batch':
    ass.c:112: warning: assignment makes pointer from integer without a cast


    Code:
    void open_batch()
    {
       FILE *fp;
       char f[100];
       char c;
       int a = 0, b = 0;
       int d, e, g, h, i, j, k, l;
       printf("Please enter the file you wish to run: ");
       scanf("%s", &f);
       if((fp = fopen(f,"rt") == NULL))    //ERROR IS HERE
       {
          printf("No such file");
       }
    
       while(fp = fopen(f,"rt") == NULL)   //ERROR ALSO HERE
       {
          c = fgetc(file);
          if((c == 70) || (c == 102) || (c == 85) || (c == 117))
          {
    Last edited by ck1; 04-01-2005 at 10:44 PM.

  2. #2
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    It's simply a warning but it would help if you showed which line the warning was on since I dunnoe which line is line 112

    Code:
       while(fp = fopen(f,"rt") == NULL)
    Should be:
    Code:
       while((fp = fopen(f,"rt")) == NULL)
    Just watch where you are "bracing" your statements.
    Also the first while loop:

    Code:
     if((fp = fopen(f,"rt") == NULL))
    Should be:
    Code:
     if((fp = fopen(f,"rt")) == NULL)
    On a side note,
    Code:
    c = fgetc(file);
    Unless you have another FILE* called file, this won't work. Use fp instead of file to read from what you opened in the if/while statements. Also why are you opening the file for reading twice?
    Last edited by 0rion; 04-01-2005 at 10:58 PM.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    i have a seg fault
    Try and keep to one thread for one question in future.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User coolshyam's Avatar
    Join Date
    Mar 2005
    Posts
    26

    Exclamation the solution

    you opened the file in the if statement. this should not be done becaus the null point assignment takes place only in the next line of comparision. you will be clear after you see my code below. trust me it works!
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main()
    {
       FILE *fp;
       char f[100];
       char c;
       int a = 0, b = 0;
       int d, e, g, h, i, j, k, l;
       printf("Please enter the file you wish to run: ");
       scanf("%s", &f);
       fp=fopen(f,"rt");              
       if(fp== NULL)    //NO MORE ERROR          
       {
          printf("No such file");
       }
    
       while(!feof(fp))   //NO MORE ERROR HERE
       {
          c = fgetc(fp);
          if((c == 70) || (c == 102) || (c == 85) || (c == 117))
          {
    		  printf("really");
    	  }
    	
       }
      
    }
    ALSO C=FGETC(FP), YOU GAVE FGETC(FILE). careful there

    any questions any type in programming

    a ready made answer
    -----------------------------------------------------------------------------------
    FORTUNE FAVOURS THE BOLD!
    -----------------------------------------------------------------------------------

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    He has done the if statement correctly but misplaced the bracket as I have already pointed out.

    Also do not use feof() to determine if you have reached EOF:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by coolshyam
    you opened the file in the if statement. this should not be done
    You know what really shouldn't be done?

    Code:
    void main()
    {
    Read the FAQ, "dear".

    Oh, while you're at it, read the one on why you don't control loops with feof.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    I really enjoy Quzah's sense of humor, at least when it isn't directed at me

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    12
    shuoldn't the scanf part read

    Code:
     scanf("%s",f);
    instead of
    Code:
     scanf("%s", &f);
    ?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > shuoldn't the scanf part read
    Yes it should read f (not &f)
    Though in this particular case, since f is an array, the result is the same.

    But it would be very wrong all of a sudden if f became a pointer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    12
    Thank you Mr. Salem for that piece of information. I didn't know that ! I should have been a member long back. Could have learned so much !

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21