
Untitled
By: a guest on
May 9th, 2012 | syntax:
None | size: 1.57 KB | hits: 16 | expires: Never
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pointers.h"
int main(int ska, char *fnames[]) {
int countLetters = 0;
int countNmb = 0;
char str[256], *word;
FILE *dfile;
int a;
int number;
char letter[5];
char first_letter[1];
struct pointer *head = NULL;
struct pointer *last = NULL;
/*duomenu failo atidarymas, jeigu nera paduoto pavadinimo is komandines eilutes, tada prasoma ivesti pavadinima*/
if (fnames[1] == NULL)
{
printf("Iveskite failo varda: ");
scanf("%s", &str);
printf("\n");
dfile = fopen(str, "r");
}
else
{
dfile = fopen(fnames[1], "r");
}
//patikrinam ar galima atidaryti faila, jeigu taip, skaitome is jo duomenis
if(dfile == NULL)
{
printf("Negalima atidaryti failo.\n");
getchar();
return 1;
}
printf("You letters:");
scanf("%s", &letter);
first_letter[0] = letter[0];
//skaitome zodzius is failo ir ziurime ar jis sudarytas tik reikiamo skaiciaus raidziu ir skaiciu
while(fscanf(dfile, "%s", str) != EOF)
{
word = (char*) malloc(strlen(str) * sizeof(char));
memcpy(word, str, strlen(str)* sizeof(char)+1);
if (word[0] == first_letter[0])
add(&head, &last, word);
free(word);
}
fclose(dfile);
sort(&head);
printf("Iveskite failo varda: \n");
scanf("%s", &str);
printf("\n");
print(&head, str);
destroy(&head);
printf("Paspauskite Enter \n");
getch();
return 0;
}