Witam. Mam za zadanie utworzenie funkcji w moim programie (zadanie na studiach). Generalnie programowanie to jest dla mnie czarna magia.
Treść zadania :
Letter filter
Write a program which filters from an input file words starting with a given
letter. The words starting with a given letter are copied to the output file. The
name of the input file follows the -i switch, the output file -o, and filtering
symbol -f. Exemplary program call:
program.exe -i input.txt -o output.txt -f a
Kod już mam napisany prawidłowo, tylko że pani profesor zażyczyła sobie abyśmy utworzyli swoją własną funkcje i wywołali ją w int main(). Podpowiedziała mi że mogę skopiować praktycznie wszystko co jest w mainie i wrzucić to do własno utworzonej funkcji. Tylko problem że nie mam zielonego pojecia jak to zrobić.. :( Pomoże ktoś?
Kod programu :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int CreateFile();
{
char litera = argv[6][0];
FILE * input;
fopen_s(&input, argv[2], "r");
if (input == NULL)
{
printf("error\n");
return 0;
}
else
{
char tab[1000];
int i = 0;
FILE*output;
fopen_s(&output, argv[4], "w");
if (output == NULL)
{
printf("error\n");
fclose(input);
return 0;
}
while (!feof(input))
{
fscanf_s(input, "%s", tab, 1000);
if (tab[0] == litera)
{
fprintf(output, "%s \n", tab);
}
}
fclose(input);
fclose(output);
}
}
int main(int argc, char** argv)
{
if (argc > 6)
{
}
else
{
printf("wrong parameters");
}
return 0;
}