I am trying to read characters and count its numbers. First, my compiler prompted me for the size of the array. I added number 50, why do I have to specify size in this case?
I have an erro message:
parse error before "char"
The line in red is the spot where the error is.
Code:
#include <stdio.h>
#include <stdlib.h>
int readline(char str[], int n);
int main()
{
char str[50];
int n;
printf("Enter your name please:\n");
scanf("%d", str);
printf("Your name has %d characters", read_line(char str[], int n));
int read_line(char str[], int n)
{
char ch;
int i = 0;
while ((ch=getchar()) != '\n')
if(i < n)
str[i++]=ch;
str[i]='\0';
return i;
}
system("PAUSE");
return 0;
}