int main(void){
	FILE *fp1, *fp2;
	if((fp1 = fopen("scrambled.txt", "r")) == NULL){
		printf("Scrambled.txt could not open.\n");
		return 0;
	}
	printf("Scrambled.txt has opened.\n");
	if((fp2 = fopen("dictionary.txt", "r")) == NULL){
		printf("Dictionary.txt could not open.\n");
		return 0;
	}
	printf("Dictionary.txt has opened.\n\n");

	char word1[20], word2[20];
	while(fscanf(fp1, "%s", word1) != EOF){
		printf("Scanning for next word.\n\n");
		printf("%s :\t", word1);
		printf("Do we have a word printed?");
		alphabetize(word1);
		while(fscanf(fp2, "%s", word2) != EOF){
			alphabetize(word2);
			if(strcmp(word1,word2) == 0)
				printf("%s\t",word2);
		}
		printf("\n");
	}
	printf("Closing files...\n\n");
	fclose(fp1);
	fclose(fp2);
	return 0;
}
예제 #2
0
파일: p8.c 프로젝트: xmonkee/datastructures
int main(int argc, char *argv[]){
  size_t n = 0; /* number of lines read */
  int s = LINES; /* initial size of array of line pointers*/
  int i;
  char *l, *line;
  charptr *linestmp;
  charptr *lines = malloc(sizeof(char*)*s); /* array storing pointers to lines */
  while(!feof(stdin) && n<LINES) {
    line = malloc(sizeof(char)*MAXLEN);
    l = fgets(line, MAXLEN, stdin); /* read a single line */
    if(l != NULL){
      lines[n++] = line; /* add it to array */
    }
  }
  
  alphabetize(lines, n);

  for(i=0; i<n; printf("%s", lines[i++]));
  return EXIT_SUCCESS;
}