#include <stdio.h>
char *fgets(char *s, int n, FILE *stream);
char *gets(char *s);
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
int main()
{
FILE *new;
char buf[100];
int n;
char *ptr = NULL;
new = fopen("new-1", "r");
if( fgets(buf, 6, new) == NULL ){
printf("the file is blank!\\n");
exit(1);
}
ptr = fgets(buf, 6, new);
printf("%s\\n",buf);
printf("%c\\n",*ptr);
printf("%c\\n",*(ptr+1) );
if( fgets(buf, 6, new) == NULL ){
printf("EOF is encountered!\\n");
exit(1);
}
return 0;
}
[root@localhost Desktop]# ./fopen_read.exe
ine!
i
n
EOF is encountered!
#include <stdio.h>
#include <string.h>
void strip_return(char *string_to_strip);
int main()
{
char tmp_str[10];
printf("Please input a string: \\n");
fgets(tmp_str, 10, stdin);
strip_return(tmp_str);
return 0;
}
void strip_return(char *string_to_strip)
{
int len;
len = strlen(string_to_strip);
printf("The input string len: %d\\n", len);
}
beyes@linux-beyes:~/C> ./string_to_strip.exe
Please input a string:
hello
The input string len: 6
if (string_to_strip[len - 1] == '\\n') string_to_strip[len - 1] = '\\0';
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |