I need help with checking my code

this is a c programming code, just trying to do something with character strings.
this code is supposed to accept a string, then show the string one word per line, but there is a bug that i cant figure out.
please help, and explain what went wrong. thanks a lot :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#define STRSIZE 81
void dispstr(char inc[STRSIZE]);
int main()
{
	void dispstr(char inc[STRSIZE]);
	char inc[STRSIZE];
	
	printf("Enter a string\n");
	gets(inc);
	
	dispstr(inc[STRSIZE]);
	
	return 0;
}

void dispstr(char inc[STRSIZE])
{
	int i=0;
	char chr;
	
	while ((chr=inc[i])!= '\0')
	{
		if (chr == ' ')
			printf("\n");
		else
			printf("%c", inc[i]);
	}
}
You need to increment i. Also no need for the 2nd forward declare (void dispstr(char inc[STRSIZE]);).

1
2
3
4
5
6
7
8
9
10
void dispstr(char inc[STRSIZE])
{
	for(int i = 0; inc[i]; ++i)
	{
		if (inc[i]== 0)
			printf("\n");
		else
			printf("%c", inc[i]);
	}
}
Topic archived. No new replies allowed.