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. ...
NullityNull's 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 ...
SuperNovaCoder's user avatar
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,...
Cliff B's user avatar
  • 68.7k
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(), ...
Cliff B's user avatar
  • 68.7k
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 ...
Cliff B's user avatar
  • 68.7k
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 ...
ChrisG's user avatar
  • 7,396
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 ...
NullityNull's user avatar
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 ... ...
Vince's user avatar
  • 142
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 ...
Cliff B's user avatar
  • 68.7k
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 ...
Blauelf's user avatar
  • 20.9k
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 ...
MARS's user avatar
  • 5,169
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 ...
DinoCoderSaurus's 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, ...
Cliff B's user avatar
  • 68.7k
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 ...
curiouskiwi's user avatar
  • 18.6k
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,...
Cliff B's user avatar
  • 68.7k
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 ...
MARS's user avatar
  • 5,169
1 vote
Accepted

problems with initials.c using strgcmp()

while(strcmp(&name[start], " ") == 0) Let's suppose: string name = bob dylan then &name[start] = ob dylan since you do start = 1 this will never be equal to " ", unless you enter two spaces ...
MARS's user avatar
  • 5,169
1 vote
Accepted

pset2: Initials - null character troubles

for (int i = 0; name[i+1] != '\0'; i++) is a bad idea, especially with that inner loop. The other case where that is bad is if you input an empty string, which the used get_string function luckily ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

initials: NUL character creating check50 error

If you look carefully, each failed test has a space at the end of the string to be processed. Look at the following code: if (name[i] == ' ' && name[i+1] != ' ') { printf("...
Cliff B's user avatar
  • 68.7k
1 vote

My string.c works only for two word string, how can i make it work on one and three word string?

I will assume you are tackling the 'less comfortable' version of the initials program, whereby you don't have to deal with extraneous whitespace. Your code is currently hard-wired to only print the ...
Steve Bunting's user avatar
1 vote

My string.c works only for two word string, how can i make it work on one and three word string?

Your while loop increments i until a space character is encountered and then you just print out (after capitalizing them) the first character in your string and the character next to the space. You ...
N. Tiwari's user avatar
1 vote

Pset2 Initials.c

It's unclear what you are trying to do with your for loops since 1) it does not advance i (i.e. it will be stuck at 0 since it ends when i<1 which is 0) and 2) you do not reference i anywhere ...
ronga's user avatar
  • 1,415
1 vote
Accepted

My code infinitely loops 'A' and I don't know why

An infinite loop happens if the while condition is never false. Be the computer. What is going to happen if your input is "a miller"? The first space is encountered when i is 1. Let's do the loop: s[...
DinoCoderSaurus's user avatar
1 vote
Accepted

In Pset2 initials, i have a segmentation fault. I really need help!

if (isupper (name)) isupper() takes a single character as input. This is trying to stuff a complete string down its throat, so it chokes and gives a seg fault. If this answers your question, please ...
Cliff B's user avatar
  • 68.7k
1 vote

still practising initials 1

First, a warning about your approach. Even though you say "practising", how will your code handle this example "robert thomas bowden" from the spec? What about "john jacob jinglehammer jones"? The ...
DinoCoderSaurus's user avatar
1 vote

nothing skip[ it gbhh

The while statement in your do/while requires some kind of test, similar to an if statement. You have a for loop setup statement where there should be a test. This is simply not going to compile. ...
Cliff B's user avatar
  • 68.7k
1 vote

initials.c accounting for when only 1 or 2 names are entered

Maybe you should consider a different approach. THe code posted above will only handle 3 names at most. What if there are more? Perhaps you should consider taking in an entire string and processing ...
Cliff B's user avatar
  • 68.7k
1 vote

pset2 initials problem

Because the psets are graded programmatically, you should make sure that you follow the instructions exactly: So that we can automate some tests of your code, your program must behave per the ...
curiouskiwi's user avatar
  • 18.6k
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'...
kzidane's user avatar
  • 17.7k
1 vote

problem with pset2 initials

I see at least two problems. First, why do you increment i at the end of this code? The for loop setup does it already. If you were doing it to skip forward a letter after printing one, it should ...
Cliff B's user avatar
  • 68.7k

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