Advertisement
Guest User

Cats

a guest
May 24th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. # include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9.     const int limit_c = 100;
  10.     const int limit_r = 100;
  11.     char names[limit_c][limit_r];
  12.     char name;
  13.     int count = 0;
  14.  
  15.    
  16.     //reads in array
  17.     while(cin.good() && count < 100)
  18.     {      
  19.         for (int i = 1; i < 100; i++)
  20.         {
  21.             count++;
  22.             cout << "Name " << i << ": ";
  23.             cin.getline(names[0],limit_r,'\n');
  24.        
  25.         }
  26.     }
  27.    
  28.     // sort
  29.    
  30.     for (int i = 0; i < count; i++)
  31.     {  
  32.         char temp[100];
  33.         for (int j = i+1; j < count; j++)
  34.         {
  35.             if (strcmp(names[i], names[j]) > 0)
  36.             {
  37.                 strcpy(temp, names[i]);
  38.                 strcpy(names[i], names[j]);
  39.                 strcpy(names[j], temp);
  40.             }
  41.         }
  42.     }
  43.  
  44.     //spits it back out and in order.
  45.     for (int i = 0; i < count; i++)
  46.     {
  47.         cout << names[i] << endl;
  48.     }
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement