# C code programming

**URL:** <https://forum.freecodecamp.org/t/c-code-programming/323876>\
**Category:** General\
**Created:** [October 24, 2019, 8:57pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876 "2019-10-24T20:57:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukea](https://avatars.discourse-cdn.com/v4/letter/l/54ee81/32.png) [@Lukea](https://forum.freecodecamp.org/u/Lukea)\
**Post date:** [October 24, 2019, 8:57pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876/1 "2019-10-24T20:57:10Z")

</div>

I am having trouble finishing my program. I am supposed to make one that prints the users name and then procedes to print out the initials. Here is my code right now:

```auto
#include <stdio.h>
#include "csc111.h"
#include <string.h>
#include <ctype.h>

int main (void) {
	
	//Declare variables
	char name[50];
	int i;
	string myString;
	string nameLength;
	
	
	//Prompt user for namespace
	printf("Please enter your name: ");
	scanf("%s", myString);
	
	
	//Load an array with letters 'a' through 'z'
	for(i=0;i<2;i++) {
		name[i] = i +97;
	}
		name[10] = '\0';
	//Convert the string to all uppercase letters
	for(i=0;i<strlen(myString);i++) {
		myString[i] = toupper(myString[i]);
	}
	while (name[i]!='\0')
	{
		if (name[i]==' ')
		{
			i++;
			printf("%s", name[i+1]);
		}
		i++;
	}
	
	printf("%c", name[i+1]);
	
	//Print initials
	printf("Your initials are: %s\n", myString);
}

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [October 24, 2019, 8:59pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876/2 "2019-10-24T20:59:04Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

**Note:** Backticks are not single quotes.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [October 24, 2019, 9:03pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876/3 "2019-10-24T21:03:57Z")

</div>

```auto
	//Load an array with letters 'a' through 'z'
	for(i=0;i<2;i++) {
		name[i] = i +97;
	}
		name[10] = '\0';
	//Convert the string to all uppercase letters
	for(i=0;i<strlen(myString);i++) {
		myString[i] = toupper(myString[i]);
	}

```

Howdy - Would you mind explaining what you are trying to do with lines 20-28? I don’t think that they help you towards printing a user name and then initials.

```auto
	while (name[i]!='\0')
	{
		if (name[i]==' ')
		{
			i++;
			printf("%s", name[i+1]);
		}
		i++;
	}

```

I think that lines 29-37 have some of the logic you need to print the initials, but I think that you are missing the first initial. You are incrementing your iterator before printing the next character when you find a space, which will cause you troubles.

```auto
	//Print initials
	printf("Your initials are: %s\n", myString);

```

Also, on line 42, you are printing the text "Your initials are: ", but you are printing `myString`, which holds the entire name the user put in.

One last note - Be careful with your print statements! `%c` isn’t the same as `%s`.

---

<div class="post-metadata">

**Author:** ![Lukea](https://avatars.discourse-cdn.com/v4/letter/l/54ee81/32.png) [@Lukea](https://forum.freecodecamp.org/u/Lukea)\
**Post date:** [October 24, 2019, 10:38pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876/4 "2019-10-24T22:38:22Z")

</div>

Hi! Thank you so much for replying to my post! I guess I tried to do something from my book in lines 20-25, but on the next few lines of code I was trying to make it print the initials capitalized. I’m really sorry if my code is messy, I am a young girl and all new to this

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [October 24, 2019, 10:50pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876/5 "2019-10-24T22:50:40Z")

</div>

No worries; we all start with messy code.

I think that I would try to get the initials printing first and then focus on capitalization. If you can find and print the initials, then you can change your code to find, capitalize, and then print the initials.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 12:58pm UTC](https://forum.freecodecamp.org/t/c-code-programming/323876/6 "2021-01-16T12:58:22Z")

</div>

Closed on January 16, 2021, 12:58pm UTC


