[問題] 一題C的作業問題
題目是這樣的..
Write a program to read a series of names, one per line, from standard input
,and write out those names spelled in reverse order to a file called file1.
Write another program to read the names in from file1, reverse them again,
sort them, and write them out to a file called file2.
我在寫file1的時候卡住了..
可以讀名字進去..但是我不會排序..
程式碼如下:
#include <stdio.h>
#include <string.h>
int main(void)
{
FILE *file;
char filename[20];
char name[20];
printf("Enter the name of the file: ");
gets(filename);
file=fopen(filename,"w");
if((file=fopen(filename,"w"))!=NULL){
printf("Enter several names:\n");
scanf("%s",name);
while(!feof(stdin)){
fprintf(file,"%s\n",name);
scanf("%s",name);
}
}
fclose(file);
return 0;
}
我不知道還要加什麼..
請大家幫忙一下..
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.130.138.118
推
09/29 20:37, , 1F
09/29 20:37, 1F
→
09/29 20:37, , 2F
09/29 20:37, 2F
→
09/29 20:38, , 3F
09/29 20:38, 3F
→
09/29 20:38, , 4F
09/29 20:38, 4F
→
09/29 20:40, , 5F
09/29 20:40, 5F
→
09/29 20:40, , 6F
09/29 20:40, 6F
→
09/29 20:41, , 7F
09/29 20:41, 7F
→
09/29 20:41, , 8F
09/29 20:41, 8F
→
09/29 20:43, , 9F
09/29 20:43, 9F
推
09/29 20:44, , 10F
09/29 20:44, 10F
→
09/29 20:44, , 11F
09/29 20:44, 11F
推
09/29 20:57, , 12F
09/29 20:57, 12F
→
09/29 20:58, , 13F
09/29 20:58, 13F
→
09/29 20:58, , 14F
09/29 20:58, 14F
→
09/29 21:00, , 15F
09/29 21:00, 15F
→
09/29 21:03, , 16F
09/29 21:03, 16F
→
09/29 21:04, , 17F
09/29 21:04, 17F
→
09/29 21:04, , 18F
09/29 21:04, 18F
→
09/29 21:05, , 19F
09/29 21:05, 19F
→
09/29 21:13, , 20F
09/29 21:13, 20F
→
09/29 21:15, , 21F
09/29 21:15, 21F
→
09/29 21:21, , 22F
09/29 21:21, 22F
推
09/29 22:12, , 23F
09/29 22:12, 23F
→
09/29 22:12, , 24F
09/29 22:12, 24F
→
09/29 22:13, , 25F
09/29 22:13, 25F
→
09/29 22:14, , 26F
09/29 22:14, 26F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章