I can't pass strings that contain an apostrophe as a command-line argument.
Here's my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned int ascii_values (const char *word);
int main (int argc, char *argv[])
{
if (argc < 2)
{
printf("Usage: ./ascii WORD\n");
}
for (int i = 1; i < argc; i++)
{
int ascii = ascii_values(argv[i]);
printf("The ascii value is %i\n", ascii);
}
}
unsigned int ascii_values (const char *word)
{
int l = strlen(word);
int ascii = 0;
for(int i = 0; i < l; i++)
{
ascii = word[i];
}
return ascii;
}
If I input the command-line arguments into the terminal:
./ascii '
The following happens and gets stuck there:
>
Instead of:
The ascii value is 39.
Any idea of why it's doing that?