P
ptq2238
Hi,
I have written this code to help me learn C but I'm not sure why gcc -
Wall is giving me an error when I compile
Basically I want to read in a character then a number and then
manipulate the number.
I've tried scanf such as scanf("%c%d",&letter,&number); but when I
type in say 2 letters instead of 1 letter and 1 number, I get a zero
for the 2nd value as it doesn't match what scanf is expecting so I'm
trying fgets.
#include <stdio.h>
#define LINESIZE 4
int main()
{
char line[LINESIZE];
int temp,temp2;
printf("Please enter a letter and a value: ");
fgets(line, LINESIZE, stdin);
printf("This line was entered: %s\n",line);
printf("line[0] is %c\n ",line[0]);
printf("line[1] is %c\n ",line[1]);
temp = atoi(line[1]);
printf("temp is %d\n ",temp);
temp2 = temp + 5;
printf("temp2 is %d\n ",temp2);
return 0;
}
Then on compile,
gcc -Wall getloc_val.c
getloc_val.c: In function `main':
getloc_val.c:17: warning: implicit declaration of function `atoi'
The book I'm refering to mentions that I can do this but why am I
getting the implicit warning ?
Pat
I have written this code to help me learn C but I'm not sure why gcc -
Wall is giving me an error when I compile
Basically I want to read in a character then a number and then
manipulate the number.
I've tried scanf such as scanf("%c%d",&letter,&number); but when I
type in say 2 letters instead of 1 letter and 1 number, I get a zero
for the 2nd value as it doesn't match what scanf is expecting so I'm
trying fgets.
#include <stdio.h>
#define LINESIZE 4
int main()
{
char line[LINESIZE];
int temp,temp2;
printf("Please enter a letter and a value: ");
fgets(line, LINESIZE, stdin);
printf("This line was entered: %s\n",line);
printf("line[0] is %c\n ",line[0]);
printf("line[1] is %c\n ",line[1]);
temp = atoi(line[1]);
printf("temp is %d\n ",temp);
temp2 = temp + 5;
printf("temp2 is %d\n ",temp2);
return 0;
}
Then on compile,
gcc -Wall getloc_val.c
getloc_val.c: In function `main':
getloc_val.c:17: warning: implicit declaration of function `atoi'
The book I'm refering to mentions that I can do this but why am I
getting the implicit warning ?
Pat