Compiling with gcc [Archive] - C Board

PDA

View Full Version : Compiling with gcc


tiberiumwaster
03-09-2002, 02:56 PM
Hi Im brandnew to both this board as to programming C I tried to write this program
with redhat 6.2

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

main()
{
char str1[] ={ 'A',' ',
'S','T','R','I','N','G',' ',
'C','O','N','S','T','A','N','T','\0'};
char str2[] = "Another string constant";
char *ptr_str = "Assign a string to a pointer";

printf("The length of str1 is: %d bytes\n",strlen(str1));
printf("The length of str2 is: %d bytes\n".strlen(str2));
printf("The length of the string assigned to ptr_str is: %d bytes\n",strlen(ptr_str));

return 0;
}

and compile it in a executable with this command

gcc -Wall -o test test.c

this is my error

request for member 'strlen' in something not a structure or union.

Now I figured out that when i want to include the lib math.h I need to add -lm at the end of the commando, but I dont know what I need to add to include the string.h, I know its probably something real stupid. But I could find the answer anywhere

Unregistered
03-09-2002, 05:34 PM
You have a typo...

On line 13 of your code, you typed in a period instead of a comma before the 'strlen'... that is why it did not recognize the function.

I compiled it on a linux and it worked fine...

Good luck

tiberiumwaster
03-11-2002, 04:27 AM
Nooo, the horror aarg :)