Advertisement
RiQ363

Untitled

Jan 19th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. // 3
  2. #include <iostream.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #define DELIMITERS " .,:;\n\t"
  9.  
  10. void function2(char *a)
  11. {
  12.   char max[20]; int i=0,j=0;
  13.   while(a[i]!='\0')
  14.   {
  15.       if (strlen(a)>j)
  16.       j=strlen(a);
  17.       max[i]=a[i];
  18.       i++;
  19.   }
  20.    printf("max length\n");
  21.    puts(max);
  22. }
  23.  
  24. void Sort(char *a[], int n)
  25. {
  26.    int i, j, k;
  27.    char min, *buf;
  28.    for(i = 0; i < n-1; i++)
  29.    {
  30.       min = a[i][0];
  31.       k = i;
  32.       for(j = i + 1; j < n; j++)
  33.          if (a[j][0] < min)
  34.          {
  35.              k = j;
  36.              min = a[j][0];
  37.          }
  38.        buf = a[i]; a[i] = a[k]; a[k] = buf;
  39.    }
  40. }
  41.  
  42. int main()
  43. {
  44. char s[500];
  45. char *a[100];
  46. char *word;
  47. int i, n = 0;
  48.   printf("Str= ");
  49.  
  50.    fgets(s,500,stdin);
  51.  
  52.    word=strtok(s,DELIMITERS);
  53.    while(word!=NULL)
  54.    {
  55.  
  56.       a[n++] = word;
  57.       word=strtok(NULL,DELIMITERS);
  58.    }
  59.    for(i = 0; i < n; i++)
  60.       puts(a[i]);
  61.    Sort(a, n);
  62.    puts("\n");
  63.    for(i = 0; i < n; i++)
  64.       puts(a[i]);
  65.       puts("\n");
  66.    function2(word);
  67.  
  68. getch();
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement