Presentation is loading. Please wait.

Presentation is loading. Please wait.

Built-in Functions for NTCAs. strlen char array[10] = “Hello”; int length = strlen(array); cout << length;

Similar presentations


Presentation on theme: "Built-in Functions for NTCAs. strlen char array[10] = “Hello”; int length = strlen(array); cout << length;"— Presentation transcript:

1 http://cs.mst.edu Built-in Functions for NTCAs

2 http://cs.mst.edu strlen char array[10] = “Hello”; int length = strlen(array); cout << length;

3 http://cs.mst.edu strlen char array[10] = “Hello”; int length = strlen(array); cout << length; hello\0???? [0][1][2][3][4][5][6][7][8][9]

4 http://cs.mst.edu strlen char array[10] = “Hello”; int length = strlen(array); cout << length; hello\0???? [0][1][2][3][4][5][6][7][8][9]

5 http://cs.mst.edu 5

6 strcpy char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source);

7 http://cs.mst.edu strcpy char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source); hey\0?????? [0][1][2][3][4][5][6][7][8][9] source:

8 http://cs.mst.edu strcpy char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source); hey\0?????? [0][1][2][3][4][5][6][7][8][9] source: Boy Howdy\0 [0][1][2][3][4][5][6][7][8][9] target:

9 http://cs.mst.edu strcpy char source[10] = “Hey”; char target[10] = “Boy Howdy”; strcpy(target, source); hey\0?????? [0][1][2][3][4][5][6][7][8][9] source: hey\0Howdy [0][1][2][3][4][5][6][7][8][9] target:

10 http://cs.mst.edu strcpy... strcpy(target, “Hi”); strcpy(target, “BurritoToppings”; Hi\0 Howdy [0][1][2][3][4][5][6][7][8][9] target:

11 http://cs.mst.edu strcpy... strcpy(target, “Hi”); strcpy(target, “BurritoToppings”; BurritoTop [0][1][2][3][4][5][6][7][8][9] target:

12 http://cs.mst.edu strcat char source[10] = “There”; char target[10] = “Hi”; strcat(target, source);

13 http://cs.mst.edu strcat char source[10] = “There”; char target[10] = “Hi”; strcat(target, source); There\0???? [0][1][2][3][4][5][6][7][8][9] source:

14 http://cs.mst.edu strcat char source[10] = “There”; char target[10] = “Hi”; strcat(target, source); There\0???? [0][1][2][3][4][5][6][7][8][9] source: Hi\0??????? [0][1][2][3][4][5][6][7][8][9] target:

15 http://cs.mst.edu strcat char source[10] = “There”; char target[10] = “Hi”; strcat(target, source); There\0???? [0][1][2][3][4][5][6][7][8][9] source: HiThere\0?? [0][1][2][3][4][5][6][7][8][9] target:

16 http://cs.mst.edu strcat... strcat(target, “!!”); strcat(target, “!”); HiThere\0?? [0][1][2][3][4][5][6][7][8][9] target:

17 http://cs.mst.edu strcat... strcat(target, “!!”); strcat(target, “!”); HiThere!!\0 [0][1][2][3][4][5][6][7][8][9] target:

18 http://cs.mst.edu strcat... strcat(target, “!!”); strcat(target, “!”); HiThere!!! [0][1][2][3][4][5][6][7][8][9] target:

19 http://cs.mst.edu 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;

20 http://cs.mst.edu 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;

21 http://cs.mst.edu 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;

22 http://cs.mst.edu 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;

23 http://cs.mst.edu 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;

24 http://cs.mst.edu 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;

25 http://cs.mst.edu 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;

26 http://cs.mst.edu 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;

27 http://cs.mst.edu 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;

28 http://cs.mst.edu 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;

29 http://cs.mst.edu 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; Take Note!

30 http://cs.mst.edu Dangers char source[10] = “Walk This Way”; char target[15]; strcpy(target, source); strcat(target, source);

31 http://cs.mst.edu Also Available  strncpy  strncmp  strncat

32 http://cs.mst.edu End of Session


Download ppt "Built-in Functions for NTCAs. strlen char array[10] = “Hello”; int length = strlen(array); cout << length;"

Similar presentations


Ads by Google