69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#define SIZE 256
int has_ch (char ch, const char *temp);
int main (int argc, char *argv[])
{
FILE *fp;
char temp[SIZE];
int i = 0;
char ch = argv[1][0];
if (argc != 3)
{
printf("filename s1 s2.....\n");
exit(1);
}
else
{
if ((fp = fopen(argv[2], "r")) == NULL)
{
printf("Can't open %s \n", argv[1]);
exit(2);
}
while (fgets(temp, SIZE, fp) != NULL)
{
if (has_ch(ch, temp))
{
fputs(temp, stdout);
}
}
}
fclose(fp);
return 0;
}
int has_ch (char ch, const char *line)
{
int i = 0;
while (line[i] != '\0')
{
if (ch == line[i])
{
return (1);
}
i++;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define SIZE 256
int main (int argc, char *argv[])
{
FILE *fp;
char temp[SIZE];
int i = 0;
char ch = argv[1][0];
if (argc != 3)
{
printf("filename s1 s2.....\n");
exit(1);
}
else
{
if ((fp = fopen(argv[2], "r")) == NULL)
{
printf("Can't open %s \n", argv[1]);
exit(2);
}
while (fgets(temp, SIZE, fp) != NULL)
{
while (temp[i] != '\0')
{
if (temp[i] == ch)
{
fputs(temp, stdout);
i = 0;
break;
}
i++;
}
}
}
fclose(fp);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define SIZE 256
int main (int argc, char *argv[])
{
FILE *fp;
char temp[SIZE];
int i = 0;
char ch = argv[1][0];
if (argc != 3)
{
printf("filename s1 s2.....\n");
exit(1);
}
else
{
if ((fp = fopen(argv[2], "r")) == NULL)
{
printf("Can't open %s \n", argv[1]);
exit(2);
}
while (fgets(temp, SIZE, fp) != NULL)
{
i=0;
while (temp[i] != '\0')
{
if (temp[i] == ch)
{
fputs(temp, stdout);
i = 0;
break;
}
i++;
}
}
}
fclose(fp);
return 0;
}