hello,
I am new here and I have a question about this code:
"
int num;
char a[4];
a[0]=9;
a[1]=4;
a[2]=NULL;
a[3]=NULL;
num=atoi(grade);
"
I have a char array (a) that have (9 4 NULL NULL) i want to extract only the 94 using atoi function.
but, when I run the program the atoi function return 0. why?
thnk you,
atoi function
Started by felixb, Mar 24 2008 04:19 AM
9 replies to this topic
#1
Posted 24 March 2008 - 04:19 AM
|
|
|
#2
Posted 24 March 2008 - 06:19 AM
You probably meant to have
a[0] = '9'; a[1] = '4'; a[2] = '\0'; a[3] = '\0';This is more easily written (as an initialized array) as:
char a[4] = "94";
#3
Posted 24 March 2008 - 09:10 AM
no... but the point is that i have array and each cell have digit...
i tried now with '\0' but it still return 0
i tried now with '\0' but it still return 0
#4
Posted 24 March 2008 - 09:35 AM
Try looking more closely at my previous response: 9 is not the same as '9'. Use copy and paste if need be.
Edited by dcs, 24 March 2008 - 09:39 AM.
#5
Posted 24 March 2008 - 09:38 AM
<<double post -- please delete>>
#6
Posted 24 March 2008 - 12:35 PM
thank you very much for your help
#7
Posted 25 March 2008 - 09:27 PM
you have used atoi(grade).
What is grade? Its not declared anywhere! Use atoi(a).A is where you stored the data!
And '\0' and NULL dont make a difference. One is a escape sequence representation and the other is a high level text, resulting both in an eof.
What is grade? Its not declared anywhere! Use atoi(a).A is where you stored the data!
And '\0' and NULL dont make a difference. One is a escape sequence representation and the other is a high level text, resulting both in an eof.
God is real... unless declared an integer
my blog :: http://techarraz.com/
#8
Posted 25 March 2008 - 09:37 PM
it's ok.
the problem was that I done a[1]=9 instead of a[1]='9'
the problem was that I done a[1]=9 instead of a[1]='9'
#9
Posted 25 March 2008 - 09:46 PM
Chinmoy said:
And '\0' and NULL dont make a difference. One is a escape sequence representation and the other is a high level text, resulting both in an eof.
:confused:
Edited by dcs, 25 March 2008 - 09:53 PM.
#10
Posted 25 March 2008 - 10:03 PM
'\0' and NULL have the same implication. Just that NULL works good with pointers and '\0' works good with char arrays.By eof here i wanted to mean end of input buffer..
God is real... unless declared an integer
my blog :: http://techarraz.com/


Sign In
Create Account

Back to top









