Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- int main(void)
- {
- FILE *fp;
- srand(time(NULL));
- char tabchar[4][256];
- char tmp[256];
- int n=0,draw;
- int size[5];
- char lastchar;
- char first_char;
- if ((fp = fopen("polski.txt","r")) == NULL)
- {
- printf("Nie udalo sie otworzyc pliku!");
- exit(0);
- }
- while(fscanf(fp,"%s",tmp) != EOF)
- {
- n++;
- }
- draw = rand()%n +1;
- int j=0;
- while (j != 4)
- {
- fseek(fp,0,0);
- if (j == 0)
- {
- for(int i = 0; i <= draw; i++)
- {
- fscanf(fp,"%s",tabchar[j]);
- }
- size[j] = strlen(tabchar[j]);
- first_char = tabchar[j][0];
- lastchar = tabchar[j][size[j]-1];
- }
- else
- {
- for( int i = 0; i <= n; i++)
- {
- fscanf(fp, "%s",tabchar[j]);
- if ( j > 1 && j <3)
- {
- if ( tabchar[j][0] == lastchar && strlen(tabchar[j]) == size[j-2] && strlen(tabchar[j])>=3)
- {
- size[j] = strlen(tabchar[j]);
- lastchar = tabchar[j][size[j]-1];
- break;
- }
- }
- else if (j = 3){
- char lastcharj;
- lastcharj =tabchar[j][size[j]-1];
- if (tabchar[j][0] == lastchar && strlen(tabchar[j]) == size[j-2] && strlen(tabchar[j])>=3 && lastcharj == first_char){
- size[j] = strlen(tabchar[j]);
- lastchar = tabchar[j][size[j]-1];
- break;
- }
- }
- else
- {
- if (tabchar[j][0] == lastchar && strlen(tabchar[j])>=3)
- {
- size[j] = strlen(tabchar[j]);
- lastchar = tabchar[j][size[j]-1];
- break;
- }
- }
- }
- }
- j++;
- }
- for (int i = 0;i < 4;i++)
- {
- printf("%s\n",tabchar[i]);
- }
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement