Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char s[80], p[4] = "app";
- char* token;
- fgets(s, 50, stdin);
- token = strtok(s, ",");
- while (token != NULL)
- {
- if (strncmp(token, p, 3) == 0)
- printf("%s\n", token);
- token = strtok(NULL, ",");
- }
- }
- ------------------------------------------
- 2)
- #include "string.h"
- #include "istream"
- int main () {
- char s[1000], p[10];
- int c = 0;
- fgets(s, 1000, stdin);
- fgets(p, 10, stdin);
- char *sl = strtok(s," ");
- int h = strlen(p) - 1;
- while (sl != NULL){
- if (strncmp(sl, p, h) == 0){
- c++;
- }
- sl = strtok(NULL," ");
- }
- printf("%d", c);
- }
- ------------------------------------------------
- 3)
- #include <stdlib.h>
- #include <string.h>
- #include <istream>
- int srt(const void* a, const void* b) {
- char** surnameA = (char**)a;
- char** surnameB = (char**)b;
- return strcmp(*surnameA, *surnameB);
- }
- int main() {
- char name[100];
- char* name1[20];
- int c = 0;
- fgets(name, 100, stdin);
- char* tok = strtok(name, ", ");
- while (tok != NULL) {
- name1[c] = strdup(tok);
- c=c+1;
- tok = strtok(NULL, ", ");
- }
- qsort(name1, c, sizeof(char*), srt);
- printf("sort:\n");
- for (int i = 0; i < c; i++) {
- printf("%s\n", name1[i]);
- free(name1[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement