Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include <malloc.h>
- int main(void)
- {
- //Задание 2. Осуществить конкатенация (сложение) первой строки и n начальных символов второй строки.
- char destination[25];
- char *source = "structured ";
- strcpy(destination, "programming");
- strncat(destination, source, 11);
- printf("%s\n", destination);
- //Задание 4. Осуществить сравнение первых n символов двух строк.
- char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
- int ppr;
- ppr = strncmp(buf2,buf1,3);
- if (ppr > 0)
- printf("buffer 2 is greater than buffer 1\n");
- else
- printf("buffer 2 is less than buffer 1\n");
- ppr = strncmp(buf2,buf3,3);
- if (ppr > 0)
- printf("buffer 2 is greater than buffer 3\n");
- else
- printf("buffer 2 is less than buffer 3\n");
- //Задание 9. Осуществить поиск в строке последнего вхождения указанного символа.
- char string[15];
- char *ptr, c = 'r';
- strcpy(string, "This is a string");
- ptr = strchr(string, c);
- if (ptr)
- printf("The character %c is at position: %d\n", c, ptr);
- else
- printf("The character was not found\n");
- //Задание 11. Определить длину отрезка одной строки, содержащего символы из множества символов, входящих во вторую строку.
- char *string1 = "1234567890";
- char *string2 = "123456";
- int length;
- length = strspn(string1, string2);
- printf("Character where strings intersect is at position %d\n", length);
- //Задание 13. Выделить из одной строки лексемы (кусочки), разделенные любым из множества символов (разделителей), входящих во вторую строку.
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement