8

I really think that is because you didn't include the correct header file, toupper() is a function declared in ctype.h you need to include this header in the code. #include <ctype.h>


7

Oh, I almost forget. Those who are struggling with this particular set, I'd suggest the following: Once you can "print" one letter of the first name (e.g. using the [0] square brackets and the first char of the array) the "real" problem is to print the "ith" character AFTER the space bar given by the user, more clearly: The user types "John Doe" you wanna ...


5

if((i = 0) || isspace(s[i - 1])) Are you testing for i == 0 or reassigning a value of 0 to i, i=0 ? It's a common mistake. A single = is an assignment, while two == signs is a logical test of whether two things are the same. The result of the error is that every time you hit the if statement, you were resetting i to 0 and creating an infinite loop. You've ...


4

if(isblank(name[i])); You put a semicolon on the end. That basically means "if( ) then do nothing." The mistake was the semicolon. By adding it, you closed the if statement code block. The code in the curly braces that follows simply becomes a block of code that is bound by the curly braces for scope purposes, but will execute every time. Next, realize ...


4

It's usually the subtle things that give people the most trouble until they're understood. if (name[i] == (int)" ") You don't realize it, but you've made a simple error. You want to compare a char to a char, but you are actually telling the compiler to compare a single char to a string. The problem is that you are using double quotes. Double quotes ...


3

In order to find where each name starts, you will have to iterate through the whole string, so yes, you will need a loop :)


3

isblank(_), like isupper() and islower(), takes a single character as an argument. You are passing it an entire string and it's choking on it, causing a seg fault. isblank(name[i]) solves the issue nicely. Also, I don't follow the reason for i++; inside the if loop. The for loop is incrementing i, so do you really want to increment it again inside the loop?...


3

When you have square brackets following the name of a variable, the compiler thinks that you are trying to declare an array of type string with name "s". But that isn't what you want to do with this. The whole name (with spaces) will be stored in that variable and what you want to do is parse the string and essentially print the initials. To do this, you ...


3

There are a few errors in your code that mess up your output. printf("%c",toupper(n[0])); has a serious error. This works for Robert Thompson but not if there was a space before Robert. It would count the space as the initial and print it out, which will cause check50 to give errors. You want the first alphabetical letter, not the first character. There are ...


2

Yes, this output. Then i think the problem is obvious. You print the initials and then the program ends and the command prompt apears in the same line than the initials. This is a piece of the especifitations for the problem set: Write, in a file called initials.c, a program that prompts a user for their name (using GetString to obtain their name as ...


2

Remove the printf function that contains "Please enter your name:", because due to the pset specs you shouldn't print anything out before reading the user's input. In order to avoid this kind of errors in the future, you will need to follow the pset specs precisely, a great tool that might help you do so, is by checking the staff's implementation of the ...


2

char* s[] = {GetString()}; That declares an array of strings, not one string. So when GetString() returns, it puts the string into s[0]. As there is only one entry in the array, that is all that s holds. In your loop, therefore, toupper(s[0][0]) will work fine, because s[0] exists. But next time through s[1] will cause a segfault, because it doesn't ...


2

First of all it's not needed to create an array to store the letters you get as initials, as this will require a bit more advanced programing, you can just print the letters to the standard output with printf. For example change this command initials[i] = toupper(name[i+1]); to printf("%c", toupper(name[i+1])); and after the for loop finishes just print ...


2

It looks to me like the string 'initials' should have a different index variable, say j instead of i. Create and initialize to zero another int called j replace initials[i] = toupper(name[i+1]); with initials[j] = toupper(name[i+1]); j++;


2

You have 2 main problems. The first one is that s[i] is a character (typically an ASCII value). If you add/subtract 1 to/from that, this will do exactly that — adding/subtracting 1 to/from this value. For example, if s[i] was 'a', that means that it stores the value 97. s[i] + 1 will be 98 which is corresponds to 'b' in the ASCII table. What you wanna do ...


2

The problem is that your structuring of the printf statement is bad. Look at the statement: printf("%s","%c", name[0],name[i+1]); It has two formatting strings, "%s" and "%c" when it is only allowed to have one. The compiler expects anything that follows the format string to be a variable to be inserted for a placeholder in the format string. It's also ...


2

Did you watch any of the videos? They often use GetString(), so you have many examples. To prompt a user for input: string s = GetString(); I saw this here: https://youtu.be/vp3TBL4WTbc?t=5s ... but there are many, many other examples if you watch the videos. Update: Maybe you meant to ask what to do with the string you get from GetString()? Iterate ...


2

You want hints? Except for the first initial, what character is always before every initial? There are a lot of library functions out there, some that you should look at now, like tolower(), isalpha(), and a whole lot more. Since you only wanted a hint, I'll let you think about what else is out there. ;-) If this answers your question, please click on ...


2

The code is on the right track, but has a few problems. THe code prints the first letter, but it does so inside the for loop. That means that it will do so for every pass through the loop. Except, it may seem that this isn't the case. That's because of the break that follows. That unconditional break will cause the loop to exit immediately, so the ...


2

Parse the string (array of chars) with a for loop. If found a space then print the following char (whether or not you check if that next char is alphabetic is up to you). A little piece of code like this would find, capitalize, and print chars that come after a space for you. (ctype.h library) if (name[i] == ' ') { printf("%c", toupper(name[i + 1])); }


2

The main problem (and probably just a misunderstanding due to lack of further knowledge) is the distinction between a char array char[], and a char pointer char*, which is typedefed as string. Your make_Initials() function returns a char * (aka string as you will learn later on) but instead you assign to final_Result a char array (char[]) and return that, ...


2

A code too complicated to print the first character in uppercase, the code is inefficient with two loops unnecessary because we know we're looking letters == 0 suppose we introduce a string from the command line. We can do more simply: #include <stdio.h> #include <string.h> #include <cs50.h> #include <ctype.h> int main(int argc, ...


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 ...


2

You should print a character s[i] if it's not space, and either the first character, or preceded by a s[i-1] being a space. You can put that into a single combined condition, and have only one output command in the loop. Don't compare index i and space, but the character s[i] and space.


2

This /n is not a new line. From the spec (emphasis added): Your program should print the user’s initials (i.e., the first letter of each word in their name) with no spaces or periods, followed by a newline (\n). Notice the two tests that fail with "junk" at the end of the output: :( outputs "MB" for " milo banana " \ expected output, but not "MB\u0000/...


2

Did the instructions say to print "What is your full name?" One of the hidden lessons of the first few psets is to write the code exactly to the specification. Any extra or missing prompts, spaces, text, chars, whitespace, line feeds, etc., will trigger a fail. If this answers your question, please click on the check mark to accept. Let's keep up on forum ...


2

(Turns out it is your code that is the problem) You declare an array c[100]. Then you check if s[0] is a space. If it isn't, you put s[0] into c[0]. That's fine. But if it's not a space, you go right into your loop: count++; z=0; c[count] = s[n+1] At this point, you increment count and c[0] has an unknown value in it, which might be an unprintable char....


2

You're right, it's something simple. %s is the placeholder for printing a string. %c is for printing a character. The variable s is for a string, but s[0] is a character, not a string. In this case, %c should be used. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)


2

The only problem is that your second IF condition is outside the For loop: if (name[i] == ' ') { printf("%c\n", name[i + 1]); so that the blank space is never reached, the solution would be to introduce it into the loop. On the other hand the statement: first_letter = name[0]; I would take it out of the loop, since you know what the index is, you do ...


1

for (int i = 0, n = strlen(s); i < n; i++) since you took care of s[0] separately (before the loop), do you think you still need to start with i = 0? if (s[i] == ' ' && s[i] != '\0') let's agree that a char variable can hold one value and only one value. in the expression s[i] == ' ' && s[i] != '\0', if s[i] == ' ' evaluates to true, ...


Only top voted, non community-wiki answers of a minimum length are eligible