320 likes | 424 Views
Built-in Functions for NTCAs. strlen. char array[10 ] = “Hello”; int length = strlen (array); cout << length;. strlen. [0]. [1]. [2]. [3]. [4]. [5]. [6]. [7]. [8]. [9]. h. e. l. l. o. . ?. ?. ?. ?. char array[10 ] = “Hello”; int length = strlen (array);
E N D
strlen char array[10] = “Hello”; int length = strlen(array); cout << length;
strlen [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] h e l l o \0 ? ? ? ? char array[10] = “Hello”; int length = strlen(array); cout << length;
strlen [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] h e l l o \0 ? ? ? ? char array[10] = “Hello”; int length = strlen(array); cout << length;
strcpy char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source);
strcpy [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] h e y \0 ? ? ? ? ? ? source: char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source);
strcpy [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] h e y \0 ? ? ? ? ? ? source: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] B o y H o w d y \0 target: char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source);
strcpy [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] h e y \0 ? ? ? ? ? ? source: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] h e y \0 H o w d y \0 target: char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source);
strcpy [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] H i \0 \0 H o w d y \0 target: ... strcpy(target, “Hi”); strcpy(target, “BurritoToppings”;
strcpy [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] B u r r i t o T o p target: ... strcpy(target, “Hi”); strcpy(target, “BurritoToppings”;
strcat char source[10] = “There”; char target[10] = “Hi”; strcat(target, source);
strcat [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] T h e r e \0 ? ? ? ? source: char source[10] = “There”; char target[10] = “Hi”; strcat(target, source);
strcat [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] T h e r e \0 ? ? ? ? source: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] H i \0 ? ? ? ? ? ? ? target: char source[10] = “There”; char target[10] = “Hi”; strcat(target, source);
strcat [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] T h e r e \0 ? ? ? ? source: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] H i T h e r e \0 ? ? target: char source[10] = “There”; char target[10] = “Hi”; strcat(target, source);
strcat [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] H i T h e r e \0 ? ? target: ... strcat(target, “!!”); strcat(target, “!”);
strcat [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] H i T h e r e ! ! \0 target: ... strcat(target, “!!”); strcat(target, “!”);
strcat [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] H i T h e r e ! ! ! target: ... strcat(target, “!!”); strcat(target, “!”);
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); cout<<strcmp(ntca1, ntca3); cout<<strcmp(ntca3, ntca1); cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); cout<<strcmp(ntca1, ntca3); cout<<strcmp(ntca3, ntca1); cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); cout<<strcmp(ntca3, ntca1); cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); cout<<strcmp(ntca3, ntca1); cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); // -1 cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); // -1 cout<<strcmp(ntca1, “bobby”); if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); // -1 cout<<strcmp(ntca1, “bobby”); // -1 if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); // -1 cout<<strcmp(ntca1, “bobby”); // -1 if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); // -1 cout<<strcmp(ntca1, “bobby”); // -1 if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
strcmp Take Note! char ntca1[20] = “bob”; char ntca2[20] = “bob”; char ntca3[20] = “Bob”; cout<<strcmp(ntca1, ntca2); // 0 cout<<strcmp(ntca1, ntca3); // 1 cout<<strcmp(ntca3, ntca1); // -1 cout<<strcmp(ntca1, “bobby”); // -1 if (!(strcmp(ntca1, ntca2)) cout<<”these strings are identical”<<endl; else cout<<”these strings are different”<<endl;
Dangers char source[10] = “Walk This Way”; char target[15]; strcpy(target, source); strcat(target, source);
Also Available strncpy strncmp strncat