Character to array (Noobie Q)
It seems as if someone else on here is doing the exact same assignment as me...haha...well...I have some different problems.
If you run this, you see that, after you enter the word, you have to hit <return> 10 times for the next "please enter your ## word" to come up. Its obviously effecting my results if you keep going through the program. (I don't know why this is). On top of that I don't want my words to exceed 9 characters, and I can't really test that yet because of my first bug.
The code with the substitution of \n to \0 was given by our prof, because we obviously have to use strings in our program. I am not sure if I placed it in my program correctly however, it makes sence. For every time 'b' increases once, 'c' will increase 9 times, and each time assigning a character to "word[b][c]" until it reaches the new line character.
(However we/nor I, have learned strings yet, so Im not trying to worry about that right now, Id just like to get the basic input and output down, before any sorting w/ strings).
ex. of what code should do
Enter ## word : FrOG
etc...
Unsorted code:
fRoggoRf
Code:
#include <stdio.h>
#include <string.h>
char word[10][19];
int a;
int b;
int c;
int d;
main (){
printf("Enter words no longer than 9 characters\n");
for (a=0; a<10; a++)
{
if (a==0)
printf("Enter your 1st word:");
else if (a==1)
printf("Enter your 2nd word:");
else if (a==2)
printf("Enter your 3rd word:");
else
printf("Enter your %dth word:", a+1);
for (b=0; b<10; b++)
for (c=0; c<10; c++)
{
word[b][c]=fgetc(stdin);
if (word[b][c]=='\n')
{
word[b][c]='\0';
break;
}
if (c>=10)
printf("You have entered a word more than 9 characters\n");
/*goto A*/
}
}
printf("\n");
printf("Unsorted Input: \n");
printf("\n");
for (b=0; b<10; b++)
{
for(c=0; c<10; c++)
{
d=word[b][c];
if (d>=65 && d<=91)
d=d+32;
else if (d>=97 && d<=124)
d=d-32;
printf("%c",d);
}
for(c=10; c<=20; c++)
{
d=word[b][c];
if (d>=65 && d<=91)
d=d+32;
else if (d>=97 && d<=124)
d=d-32;
printf("%c",d);
}
}
return 0;
}
I like finding the errors, so if its a simple syntax error, just give me the line # and ill try to figure it out. But if its all mashed up, well then any adivce would be very helpful. Thank you.