I'm trying to run an isalpha check on an entered string but the issue is, that isalpha works only for individual characters apparently. If I run it like this on a string, I get a segmentation fault.
There might be a more elegant solution, but I can not find a way to connect the string with the char array which is the only missing piece
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int i;
int main (void)
{
string text = get_string("Text:
");
int lenght = strlen(text);
if(isalpha(text))
{
printf("Well done");
}
else
{
printf("You suck");
}
So I tried to transform the string into each individual char array. dispate the fact that there might be a more elegant solution, I can not find a way to connect the string with the char array which is the only missing piece
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int i;
int main (void)
{
string text = get_string("Text:
");
int lenght = strlen(text);
char letter[lenght];
for(i = 0; i < lenght; i++)
{
printf("Letter %i is %c
", i, letter[i]);
}
}
Any piece of advice how I can run the isalpha check on my string before I continue to the actual function?