English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2007-02-13 04:32:02 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

There is no string function you have to use character arrays.

RJ

2007-02-13 04:41:00 · answer #1 · answered by Anonymous · 1 1

This depends on what you are trying to do.
You must include strng.h at the top of your file e.g.
#include

A string is a null terminated char array e.g.
char mystr[80] = "Hello World";
/* mystr is = "Hello World\0" */
mystr[5] = '\0'; /* Null terminated so the string is now Hello*/

Look here http://www.opengroup.org/onlinepubs/007908799/xsh/string.h.html for explanations of the functions but basicall you use them like:-

#include

void main(void) {
char str1[80] = "A String";
char str2[80] = "Another String";

if (strcmp(str1, str2) == 0)
printf ("They are the same\n");
else
printf ("They are different\n");

if (strncmp(str1, str2, 1) == 0)
printf ("The first character is the same\n");
else
printf ("The first character is different\n");

}

2007-02-14 04:59:22 · answer #2 · answered by Tempest 3 · 0 0

There is no string datatype in C, but there are several functions that work with "strings" (arrays of characters with a null terminator). For example, strcmp, strncmp, strcpy, etc.

Are you referring to these?

2007-02-13 12:49:05 · answer #3 · answered by BigRez 6 · 2 0

fedest.com, questions and answers