Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16420

My for-loop (in c language) is not looping in vscode

$
0
0

In my code below, I'm trying to check whether each char in the string array is alphabetical or not by creating a bool function. But when I run the program, my bool function is not looping through the string array and only checks the first char in the string array. Further debugging also shows that the function is indeed not looping through the string array.

p.s this is a test i made for a CS50 problem.

#include <cs50.h>#include <string.h>#include <ctype.h>#include <stdio.h>bool only_alpha(string a);int main(void){    string s = get_string("String: ");    if(only_alpha(s))    {        printf("Yes\n");    }    else    {        printf("No\n");    }}bool only_alpha(string a){    int q = strlen(a);    //check if each char in string is alphabetical    for(int i = 0; i < q; i++)    {        if(isalpha(a[i]))        {            return true;        }        else        {            return false;        }    }    return 0;}

this is what i get when I run the program.enter image description here

I've used for-loops before and I don't know what I'm doing wrong, and I'm starting to think it's a VScode problem (after a new update) because I've used this exact code (but with isdigits).Please help!!!


Viewing all articles
Browse latest Browse all 16420

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>