Home > Software design >  I was trying to declare a function which takes a string as an input and give an int as an output
I was trying to declare a function which takes a string as an input and give an int as an output

Time:08-16

my code is not identifying type string. I am using c to program

[]

CodePudding user response:

Parameter types are only put in function declarations, not function calls.

int letters = count_letters(string text);

should be

int letters = count_letters(text);

CodePudding user response:

C does not have a string type.

Although in C you can use the types char * and char[] to store and manipulate array of characters and treat them like strings.

define a string like this:

char *x = "hello"; // cannot be edited treat as read only (in most cases)
char x[5] = "hello";
char[5] = {'h','e','l','l','o','\0'}; // character at end signifies end of string 
  • Related