Task
Implement the main function
is_asciifunction is provided- Accept a single command line argument (string)
- Call
is_asciion that argument - Print
1if the string is ASCII, or0otherwise
Test
$ ./is_ascii hello
1
$ ./is_ascii café
0
$ ./is_ascii ASCII
1
$ ./is_ascii 😊
0Code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int is_ascii(char* str) {
while (*str) {
if ((unsigned char)*str > 127) {
return 0;
}
str++;
}
return 1;
}
int main(int argc, char** argv) {
printf("%d\n", is_ascii(argv[1]));
return 0;
}