Please, z is returning zero. Would love an explanation with a fix.Code:#include <stdio.h> #include <stdlib.h> int main(void) { char input[100]; int z; printf("Insert string: "); scanf("%s", input); z = atoi(input); printf("%d", z); return 0; }
Please, z is returning zero. Would love an explanation with a fix.Code:#include <stdio.h> #include <stdlib.h> int main(void) { char input[100]; int z; printf("Insert string: "); scanf("%s", input); z = atoi(input); printf("%d", z); return 0; }
atoi(3) - Linux manual page
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
I suggest you post the input with the output you want because what you stated is not clear to me.
To me char is already ASCII!
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
Perhaps you want to print the value of each character?
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char input[100]; printf("Insert string: "); scanf("%99s", input); for(size_t i = 0; i < strlen(input); ++i) printf("%c = 0x%X = %d\n", input[i], (int)input[i], (int)input[i]); return 0; }
convert CHAR into ASCIIC - Type Casting - TutorialspointCode:#include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char input[100]; printf( "String: " ); scanf( "%s", input ); for (int i=0; i<strlen(input); i++) { int z = (int)(input[i]); printf( "%i,", z ); } printf( "\n" ); return 0; }
Last edited by Structure; 06-14-2021 at 05:12 AM.
"without goto we would be wtf'd"
atoi & scanfCode:#include <stdio.h> #include <stdlib.h> int main( int argc, char *argv[] ) { char number[128]; printf( "Enter Number: "); scanf( "%s", number); int z = atoi( number ); printf( "%i \n", z ); return 0; }
"without goto we would be wtf'd"
Looks good, thanks to all those that helped! Great to be back on the forum!