Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <malloc.h>
  5.  
  6. int main(void)
  7. {
  8.         //Задание 2.     Осуществить конкатенация (сложение) первой строки и n начальных символов второй строки.
  9.         char destination[25];
  10.     char *source = "structured ";
  11.     strcpy(destination, "programming");
  12.     strncat(destination, source, 11);
  13.     printf("%s\n", destination);
  14.  
  15.         //Задание 4.     Осуществить сравнение первых n символов двух строк.
  16.  
  17.          char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
  18.    int ppr;
  19.    ppr = strncmp(buf2,buf1,3);
  20.    if (ppr > 0)
  21.       printf("buffer 2 is greater than buffer 1\n");
  22.    else
  23.       printf("buffer 2 is less than buffer 1\n");
  24.  
  25.    ppr = strncmp(buf2,buf3,3);
  26.    if (ppr > 0)
  27.       printf("buffer 2 is greater than buffer 3\n");
  28.    else
  29.       printf("buffer 2 is less than buffer 3\n");
  30.  
  31.  
  32.         //Задание 9.     Осуществить поиск в строке последнего вхождения указанного символа.
  33.    char string[15];
  34.    char *ptr, c = 'r';
  35.    strcpy(string, "This is a string");
  36.    ptr = strchr(string, c);
  37.    if (ptr)
  38.          printf("The character %c is at position: %d\n", c, ptr);
  39.    else
  40.     printf("The character was not found\n");
  41.    //Задание 11. Определить длину отрезка одной строки, содержащего символы из множества символов, входящих во вторую строку.
  42.  
  43.    char *string1 = "1234567890";
  44.    char *string2 = "123456";
  45.    int length;
  46.    length = strspn(string1, string2);
  47.    printf("Character where strings intersect is at position %d\n", length);
  48.    //Задание 13. Выделить из одной строки лексемы (кусочки), разделенные любым из множества символов (разделителей), входящих во вторую строку.
  49.    char input[16] = "abc,d";
  50.    char *p;
  51.    p = strtok(input, ",");
  52.    if (p) printf("%s\n", p);
  53.    p = strtok(NULL, ",");
  54.    if (p)   printf("%s\n", p);
  55.    getch();
  56.    return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement