T
tigrfire
I need the following code to return a string of character stored in
array and also return the size of the array. I want to do it without
using pointers and so far have the character storing working fine, it's
just that I can't really think of a way to return the number of
characters in the array. Anyone help me out?
int inputPhrase()
{
char msg[characters], ch;
int i = 0;
int n = 5;
while ((ch = getchar()) != '\n')
{
msg[i++] = ch;
}
msg = '\0'; /* prevents garbage from being place at end of array
output */
i = 0;
while (msg != '\0')
{
printf("%c", msg[i++]);
}
return n;
}
int main()
{
inputPhrase();
int size = inputPhrase();
printf("%d\n", size);
return 0;
}
array and also return the size of the array. I want to do it without
using pointers and so far have the character storing working fine, it's
just that I can't really think of a way to return the number of
characters in the array. Anyone help me out?
int inputPhrase()
{
char msg[characters], ch;
int i = 0;
int n = 5;
while ((ch = getchar()) != '\n')
{
msg[i++] = ch;
}
msg = '\0'; /* prevents garbage from being place at end of array
output */
i = 0;
while (msg != '\0')
{
printf("%c", msg[i++]);
}
return n;
}
int main()
{
inputPhrase();
int size = inputPhrase();
printf("%d\n", size);
return 0;
}