0

I've spent maybe 17 hours so far on this 8 of them straight. This is my code:

#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void);
int i, n;
{
        {
            printf("Please enter your name. \n");
        }
    string name = GetString();
    printf("%c", toupper(name[0]));
    for ( int i = 0, n = strlen(name); i < n; i++)
    {
        if ( name[i] == ' ' && name[i + 1] != '\0') 
        {
            printf("%c",toupper(name[i + 1])); 
            i++;

        }
    }
    printf("\n"); 
}

I get this error:

~/workspace/pset2/ $ make Initials
clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    Initials.c  -lcrypt -lcs50 -lm -o Initials
Initials.c:8:1: error: expected identifier or '('
{
^
1 error generated.
make: *** [Initials] Error 1

Please help!!!

Any other tips to improve my code would be greatly appreciated!

-Jonathan

1 Answer 1

2

Your problem is completely structural and lies here:

int main(void);

The semicolon in this line marks the end of main. (When you learn functions, it would also mark the end of a function signature line, but more on that in later weeks.) The first thing that should follow this line is an opening curly brace.

int main(void)
{
    //all of main's code goes between these curly braces.
}

Also, the curly braces around the first printf statement are unnecessary. There may be other issues, but they're for a new question. This will get you going again.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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