CyberSlug Rules!

Beginner Programming CMPS060

Prof. Paulo Franca

Home

Syllabus

Login

Objects

Download

Staff only

String functions

strings or character arrays, cannot be operated as simply as a single variable. For example, if name1 and name2 are character strings, the following operations are not possible:

name1=name2;
name1="Bill Doors";
if(name1== "Rudolph") ...

In order to operate with strings, we have to manipulate one character at a time.

string functions are available in <string.h>

  • strcmp(str1,str2) - to compare strings alphabetically;
  • stricmp(str1,str2) - to compare alphabetically disregarding case;
  • strcpy(dest,source) - copy a string into another;
  • strcat(dest,source) - appends a string to another;
  • strlen(str1) - computes the length of a string