-
atoi & scanf
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.
-
-
Quote:
Originally Posted by
stahta01
T
This actually isn't what I want. I wanted to write a program to convert CHAR into ASCII code.
-
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.
-
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;
}
-
Quote:
convert CHAR into ASCII
Code:
#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;
}
C - Type Casting - Tutorialspoint
-
Code:
#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;
}
-
Looks good, thanks to all those that helped! Great to be back on the forum!