string h include string h include stdio h Slides: 15 Download presentation : ובה פונקציות שימושיות רבות string. h יש ספריה בשם #include <string. h> #include <stdio. h> int main() { char s 1[] = “A string. ”; char s 2[] = “Another string. ”; char s 3[100] = {0}; int l 1 = strlen(s 1); int l 2 = strlen(s 2); strcpy(s 3, s 1); strcat(s 3, s 2); if (!strcmp(s 3, s 1)) printf(“%s = %s”, s 3, s 1); return 0; . © כל הזכויות שמורות. נכתב ע"י יעל ארז } 8 int main() ניהול מערך של שמות { int n; scanf("%d", &n); char** names=(char**)malloc(sizeof(char*)*n); if (!names) return 1; init_arr(names, n); add_name("Danny", names, n); add_name("Yosi", names, n); add_name("Danny", names, n); del_name("Danny", names, n); free_arr(names, n); return 0; . © כל הזכויות שמורות. נכתב ע"י יעל ארז 11 } void init_arr(char *arr[], int n) { for (int i = 0; i < n; i++) arr[i] = NULL; } void free_arr(char *arr[], int n) { for (int i = 0; i < n; i++) { if (arr[i]) free(arr[i]); } free(arr); . © כל הזכויות שמורות. נכתב ע"י יעל ארז } 12 int add_name(char* name, char *names[], int n) { int i; for (i = 0; names[i]; i++); if (i == n) return -1; int len = strlen(name); names[i] = (char*)malloc(sizeof(char)*(len + 1)); if (!names[i]) return -1; strcpy(names[i], name); return i; }. © כל הזכויות שמורות. נכתב ע"י יעל ארז 13 void del_name(char* name, char *names[], int n) { int i; for (i = 0; i<n; i++) { if (!strcmp(names[i], name)) break; } if (i == n) return; free(names[i]); names[i] = NULL; }. © כל הזכויות שמורות. נכתב ע"י יעל ארז 14 #include stdio.h #include stdlib.h int main()#include #include #include #include #include #include String.h#include stdio.h #include conio.h #include stdlib.hInclude stdlib.hInclude stdio.h#indudeLicenseid=string&content=string&/paramsxml=string#include #include using namespace std;Include #include iostream #include string using namespace std#include iostream.h using namespace std#include #include #include #include stdio h