DerangedDingo
August 12th, 2007, 05:43 AM
I was trying to make a simple C program that converts a character to hex or to ASCII, by giving you the choice (although I'm not sure if it's possible to convert a key to hex.. I don't know much about it)
I'm getting the warning:
Convert.c:21: warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast
It's just a warning, so the program compiles, but then it crashes immediately after printing "You pressed the blah character"
Here's the source:
/* Small program for converting values. My first attempt at 'if' and I haven't read the chapter that introduces it. I just skipped over to find the format.
<stdlib.h> is for atoi, though I think my version of gcc doesn't need that library
Made by DerangedDingo */
#include <stdio.h>
#include <stdlib.h>
int main()
{
char key;
char num;
int decide;
printf("Press a key you want converted to ASCII or hex. ");
key=getchar();
printf("The %c key was entered.\n",key);
printf("Press 1 if you want ASCII, 2 for hex. ");
num=getchar();
decide=atoi(num);
if(decide==1)
{
printf("The value of %c in ASCII is %i.\n",key,key);
}
if(decide==2)
{
printf("The value of %c in hexadecimal is %x.\n",key,key);
}
return(0);
}
Would anyone here be kind enough to point out the problem for me?
I don't fully understand the warning message gcc gives
Thanks
(My guess is it's something with my variables)
I'm getting the warning:
Convert.c:21: warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast
It's just a warning, so the program compiles, but then it crashes immediately after printing "You pressed the blah character"
Here's the source:
/* Small program for converting values. My first attempt at 'if' and I haven't read the chapter that introduces it. I just skipped over to find the format.
<stdlib.h> is for atoi, though I think my version of gcc doesn't need that library
Made by DerangedDingo */
#include <stdio.h>
#include <stdlib.h>
int main()
{
char key;
char num;
int decide;
printf("Press a key you want converted to ASCII or hex. ");
key=getchar();
printf("The %c key was entered.\n",key);
printf("Press 1 if you want ASCII, 2 for hex. ");
num=getchar();
decide=atoi(num);
if(decide==1)
{
printf("The value of %c in ASCII is %i.\n",key,key);
}
if(decide==2)
{
printf("The value of %c in hexadecimal is %x.\n",key,key);
}
return(0);
}
Would anyone here be kind enough to point out the problem for me?
I don't fully understand the warning message gcc gives
Thanks
(My guess is it's something with my variables)