0
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>

main(int argc, string argv[])
{
    string First_name[N];
    string Last_name[N];
    int N = 0;

    {

        printf("First name: \n");
        First_name[N]= GetString();

        printf("Last name: \n");
        Last_name[N]= GetString();
    }
    printf("%d%d\n", isupper(First_name[0]), isupper(Last_name[0]));

}

this is my code for printing the initials of user's name. but the compiler outputs this error.where did i go wrong?

/home/ubuntu/workspace/pset2/ $ make initials
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    initials.c  -lcs50 -lm -o initials
initials.c:5:1: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
main(int argc, string argv[])
^
initials.c:7:23: error: use of undeclared identifier 'N'
    string First_name[N];
                      ^
initials.c:8:22: error: use of undeclared identifier 'N'
    string Last_name[N];
                     ^
3 errors generated.
make: *** [initials] Error 1
/home/ubuntu/workspace/pset2/ $ 

1 Answer 1

0

The compiler says that you're using an undeclared identifier, N. The reason is that you're trying to use N before you actually declare it. Move the declaration statement, int N = 0; up above the declaration of First_name and this problem goes away.

On a side note, it looks like you've missed the point of the assignment. It should take in a single string, find the first letter of each word or name and print out that letter as a capital letter. It should be able to handle any number of names in that string. How would your code handle the case of a middle name, or multiple middle names?

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

1
  • is there a way i can check for space in between the names inputted by the user and tell C to print the first character after the space?
    – Jerey
    Sep 7, 2016 at 3:18

You must log in to answer this question.

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