0

I'm having correct outputs using my code below however it isn't checking. Why is this happening? Thanks

#include <stdio.h>
#include <cs50.h>
#include <string.h>

#define TRUE 1
#define FALSE 0


int main(void)
{
    string s=0, supper=0;
    int inword=TRUE;
    int i,j = 0;

    printf("User complete name:\n");
    s = GetString();

    //Line added for avoiding core dumping for the string supper. Couldn't solve this problem
    supper = s;

    //Correcting Uppercase and Lowercase letters
    for(i=0;i<=strlen(s);i++)
    {


        if (i==0 && (s[i]>=97 && s[i]<=122)) s[i]=s[i]-32; //if initial and lower set upper

        if (inword == FALSE && (s[i]>=97 && s[i]<=122)) s[i]=s[i]-32; //if after a space and lower set upper

        if (i>0 && inword == TRUE && (s[i]>=65 && s[i]<=90)) s[i]=s[i]+32; //if inword and upper set lower

        if (s[i] == ' ') inword = FALSE;
        else inword = TRUE;
    }


    //Copying to supper the Initials from s.
    for(i=0;i<=strlen(s);i++)
    {

        if (s[i]>=65 && s[i]<=90) //if not UPPER
        {
            supper[j]=s[i];
            j++;

        }

    }

    //Removing extra characters from supper
    for(i=0;i<=strlen(s);i++)
    {
        if (!(supper[i]>=65 && supper[i]<=90))
        {
            supper[i] = '\n';
            supper[i+1]='\0';
            break;
        }

    }

    printf("%s\n",supper);

Correct output but not checking

1

Your output needs to be exactly what is asked for in the instructions.

username@ide50:~/workspace/pset2 $ ./initials
Zamyla Chan
ZC
username@ide50:~/workspace/pset2 $ ./initials
robert thomas bowden
RTB

For the same example, your output will look like:

username@ide50:~/workspace/pset2 $ ./initials
User complete name:
Zamyla Chan
ZC
username@ide50:~/workspace/pset2 $ ./initials
User complete name:
robert thomas bowden
RTB

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .