Фраза "Структурная переменная описывается с помощью переменной структурного типа" на мой Взгляд является тафтология. Из нее сложно понять суть утверждения. Хотелось бы полке понятного описания. |
Опубликован: 26.08.2005 | Уровень: для всех | Доступ: платный | ВУЗ: Новосибирский Государственный Университет
Лекция 13:
Символьные строки и функции над ними
strrchr - найти в строке последнее вхождение символа с.
Определение: char *strrchr(s,c) char *s; int c;
Пример 9:
#include <string.h> #include <stdio.h> #include <conio.h> int main(void) { clrscr(); char string[20]; char *ptr, c = 'r'; strcpy(string, "This is a string"); ptr = strrchr(string, c); if (ptr) printf("The character %c is at position: %d\n", c, *ptr); else printf("The character was not found\n"); getch(); return 0; }
strpbrk - найти в строке s1 любой из множества символов, входящих в строку s2.
Определение: char *strpbrk(s1,s2) char *s1, *s2;
Пример 10:
#include <stdio.h> #include <string.h> #include <conio.h> int main(void) { clrscr(); char *string1 = "abcdefghijklmnopqrstuvwxyz"; char *string2 = "onm"; int *ptr; ptr = strpbrk(string1, string2); if (ptr) printf("strpbrk found first character: %c\n", *ptr); else printf("strpbrk didn't find character in set\n"); getch(); return 0; }
strspn - определить длину отрезка строки s1, содержащего символы из множества, входящих в строку s2.
Определение: int strspn(s1,s2) char *s1, *s2;
Пример 11:
#include <stdio.h> #include <string.h> #include <alloc.h> #include <conio.h> int main(void) { clrscr(); char *string1 = "1234567890"; char *string2 = "123DC8"; int length; length = strspn(string1, string2); printf("Character where strings differ is at position %d\n", length); getch(); return 0; }
strcspn - определить длину отрезка строки s1, не содержащего символы cтроки s2.
Определение: int strcspn(s1,s2) char *s1, *s2;
Пример 12:
#include <stdio.h> #include <string.h> #include <alloc.h> #include <conio.h> int main(void) { clrscr(); char *string1 = "1234567890"; char *string2 = "747DC8"; int length; length = strcspn(string1, string2); printf("Character where strings intersect is at position %d\n", length); getch(); return 0; }
strtok - выделить из строки s1 лексемы, разделенные любым из множества символов, входящих в строку s2.
Определение: char *strtok(s1,s2) char *s1, *s2;
Пример 13:
#include <string.h> #include <stdio.h> #include <conio.h> int main(void) { clrscr(); char input[16] = "abc,d"; char *p; p = strtok(input, ","); if (p) printf("%s\n", p); p = strtok(NULL, ","); if (p) printf("%s\n", p); getch(); return 0; }