مثال مطرح شده در کلاس برای کار با رشته ها:
#include <stdlib.h> #include <stdio.h> #include <string.h> using namespace std; int main() { //khosravi.blog.ir char s1[20] = ""; char s2[20] = ""; char s3[40] = ""; printf("\nPlease enter 2 strings less than 20 characters\n"); scanf("%s", s1); scanf("%s", s2); if(strcmp(s1, s2) == 0) printf("\nTwo strings are equal"); else printf("\nTwo strings are not equal"); strcpy(s3, s1); strcat(s3, " "); strcat(s3, s2); printf("\ns3 = %s", s3); getchar(); return 0; }