-
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);
}
-
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.
-
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?
-
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.
-
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.