- 论坛徽章:
- 0
|
- #include <stdio.h>
- main ()
- {
- int i, flag;
- char str[80], c;
- FILE *fp;
- fp = fopen ("text", "w+" );
- for (flag = 1; flag;)
- {
- printf ("\n输入字符串:\n" );
- gets (str);
- printf("str[0] is %d\n",str[0]);
- fprintf (fp, "%s", str);
- printf ("继续?\n" );
- if (((c = getchar ()) == 'n' ) || (c == 'N'))
- flag = 0;
- if((c=getchar ())=='\n')
- puts("newline");
- }
- fseek (fp, 0, 0);
- while (fscanf (fp, "%s", str) != EOF)
- {
- for (i = 0; str[i] != '\0'; i++)
- if ((str[i ] >= 'a') && (str[i ] <= 'z'))
- str[i ] -= 32;
- printf ("\n%s\n", str);
- }
- fclose (fp);
- }
复制代码
试验看看... |
|