u936293
u936293

Reputation: 16264

Cannot compile: unknown type name 'string'

I have a simple C program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argCount, string args[])
{
 // ....
}

My make file is:

TARGET = test
all: $(TARGET)
$(TARGET): $(TARGET).c
     cc -g -std=gnu99 -o $(TARGET).out $(TARGET).c -lm

It gives a compilation error: unknown type name 'string' at the args parameter of main.

What else must be included to be able to use string?

Upvotes: 0

Views: 43446

Answers (2)

AmazingCarpet
AmazingCarpet

Reputation: 1

There is no type named string in c. If it's from school, there's probably an already included typedef somewhere of "string" in a header file:

#define MAX_CHAR 100 typedef char string[MAX_CHAR+1];

Upvotes: 0

luk32
luk32

Reputation: 16090

There is no type named string in c. C language use null-terminated array of characters as strings. So does the whole string.h.

Look at any function definition e.g.: strlen - size_t strlen( const char *str );.

I guess you could use write a typedef for it such as typedef char* string; but I would advise against it. It would introduce too much confusion in my opinion.

So your code should look like:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argCount, const char* args[])
{
 // ....
 return 0; // don't forget it other wise your app will spit some random exit code
}

Upvotes: 4

Related Questions