Thread: Error ???

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    53

    Error ???

    can anyone tell me what's wrong with this. My compiler for some reason only tells me that I have a couple "invalid lvalue in assignment" and "conflicting types for int_check", but it will not give me the lines. Thanks


    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    void int_check(char [], int *, int *);
    
    int main()  {
    
    char strg[20];
    int str_int=0,i,len,flag;
    
    gets(strg);
    
    int_check(strg,&str_int,&flag);
    
    if(flag==-1)
      printf("ERROR");
    else
      printf("%d\n",str_int);
    }
    
    
    void int_check(char strg, int *str_int, int *flag) {
    int len,i;
    
    len=strlen(strg);
    
    for(i=0; i<len; i++)  {
      if(isdigit(strg[i]))
        &flag=1;
      else  {
        &flag=-1;
        break;
      }
    
       
    if (*flag==-1)
      break;
    else
     &str_int=atoi(strg);
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) gets(strg);

    Never use gets. It doesn't check boundries and will trash your memory if I decide to type more than you want me to.

    2) &flag=1;
    3) &str_int=atoi(strg);

    What is the & sign supposed to be doing here?

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

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    53
    Thanks for the heads up on gets(). I can fix that on my own, the & is storing the answer in the address of flag and str_int so that main () can use the newly stored values. Any suggestions on how to fix it?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No, the & gives you the address of a variable, not what it is pointing at. The * is used to "dereference", or to produce whatever variable the pointer is pointing at. That is how you do it. Here's an example:

    int x;
    int *y;

    x = 10; //assign 10 to x
    y = &x; //put the address of x in the pointer

    *y = 11; //make x equal 11


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

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    53

    Smile Thank you quzah

    Thank you so much. I got it working. I think I am beginning to get a small grasp of this programming thing. By the way, on another note, does anyone know what the envelopes with a black hole in them mean and what all of the other icons are for. I did a search for a key to the symbols, but was unable to find it. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM