Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.57 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "pointers.h"
  5.  
  6.  
  7. int main(int ska, char *fnames[]) {
  8.         int countLetters = 0;
  9.         int countNmb = 0;
  10.         char str[256], *word;
  11.         FILE *dfile;
  12.         int a;
  13.         int number;
  14.         char letter[5];
  15.         char first_letter[1];
  16.  
  17.     struct pointer *head = NULL;
  18.     struct pointer *last = NULL;
  19.  
  20.     /*duomenu failo atidarymas, jeigu nera paduoto pavadinimo is komandines eilutes, tada prasoma ivesti pavadinima*/
  21.     if (fnames[1] == NULL)
  22.     {
  23.         printf("Iveskite failo varda: ");
  24.         scanf("%s", &str);
  25.         printf("\n");
  26.         dfile = fopen(str, "r");
  27.     }
  28.     else
  29.     {
  30.         dfile = fopen(fnames[1], "r");
  31.     }
  32.  
  33.     //patikrinam ar galima atidaryti faila, jeigu taip, skaitome is jo duomenis
  34.     if(dfile == NULL)
  35.     {
  36.         printf("Negalima atidaryti failo.\n");
  37.         getchar();
  38.         return 1;
  39.     }
  40.  
  41.     printf("You letters:");
  42.         scanf("%s", &letter);
  43.         first_letter[0] = letter[0];
  44.  
  45.     //skaitome zodzius is failo ir ziurime ar jis sudarytas tik reikiamo skaiciaus raidziu ir skaiciu
  46.     while(fscanf(dfile, "%s", str) != EOF)
  47.     {
  48.         word = (char*) malloc(strlen(str) * sizeof(char));
  49.         memcpy(word, str, strlen(str)* sizeof(char)+1);
  50.         if (word[0] == first_letter[0])
  51.             add(&head, &last, word);
  52.         free(word);
  53.  
  54.     }
  55.   fclose(dfile);
  56.  
  57.   sort(&head);
  58.  
  59.     printf("Iveskite failo varda: \n");
  60.     scanf("%s", &str);
  61.     printf("\n");
  62.     print(&head, str);
  63.  
  64.   destroy(&head);
  65.   printf("Paspauskite Enter \n");
  66.   getch();
  67.   return 0;
  68. }