8 votes
Accepted

Implicit declaration of function 'topper' is invalid in C99

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>
user avatar
  • 1,359
7 votes

Initials (Pset2) Problem

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 ...
user avatar
5 votes
Accepted

Pset2 Initials First letter only spam result

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 ...
user avatar
  • 63.1k
4 votes
Accepted

pset2 initials isblank

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 ...
user avatar
  • 63.1k
4 votes
Accepted

Pset 2 Initialise: "result of comparison against a string literal is unspecified"

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 ...
user avatar
  • 63.1k
3 votes

Initials (Pset2) Problem

In order to find where each name starts, you will have to iterate through the whole string, so yes, you will need a loop :)
user avatar
  • 1,677
3 votes
Accepted

pset2 initializing segmentation fault

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 ...
user avatar
  • 63.1k
3 votes

Pset2: Initializer list problem

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. ...
user avatar
3 votes
Accepted

Cs50 problem set 2 Initials

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 ...
user avatar
2 votes
Accepted

Why "MB" is not correct for check50's: 'outputs "MB"'?

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 ...
user avatar
  • 1,359
2 votes

pset2 initials compiles and outputs correct but errors

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 ...
user avatar
  • 47
2 votes
Accepted

pset 2: initials.c has segmentation fault (core dumped)

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 ...
user avatar
  • 18.3k
2 votes
Accepted

Unexpected outputs - initials.c

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 ...
user avatar
  • 7,326
2 votes

Unexpected outputs - initials.c

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]); ...
user avatar
  • 21
2 votes
Accepted

Pset2, initials.c, program runs but getting bizarre outputs.

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. ...
user avatar
  • 17.3k
2 votes
Accepted

pset2 initialis

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 ...
user avatar
  • 63.1k
2 votes
Accepted

Pset2: Trouble prompting user for input

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 ... ...
user avatar
  • 142
2 votes

Getting initials from a name

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(), ...
user avatar
  • 63.1k
2 votes

Code i implemented for initials.c

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,...
user avatar
  • 63.1k
2 votes
Accepted

pset2: "initials" string usage problem

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 ...
user avatar
2 votes

error in initials.c when I use my own functions

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 ...
user avatar
  • 7,326
2 votes
Accepted

Intitials.C Works With Command Line Arguments - How do I make it work with a prompt?

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 ...
user avatar
  • 5,172
2 votes

Need help with pset2 Initials!

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 ...
user avatar
  • 63.1k
2 votes
Accepted

help with pset2 initials

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 ...
user avatar
  • 20.7k
2 votes
Accepted

Pset 2 - Initials help

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 ...
user avatar
2 votes
Accepted

pset 2 initials (less); "expected prompt for input, not output of..."

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, ...
user avatar
  • 63.1k
2 votes
Accepted

expected output, but not "MB\n"

(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 ...
user avatar
  • 18.3k
2 votes
Accepted

Access array element by index ERROR

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,...
user avatar
  • 63.1k
2 votes
Accepted

Initials: Not printing second initial

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 ...
user avatar
  • 5,172
1 vote

problem with pset2 initials

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'...
user avatar
  • 17.3k

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