Beruflich Dokumente
Kultur Dokumente
if(strchr("hello", 'e'))
printf("e is in hello\n");
return 0;
} Use fwrite and fread to save
and read
#include <stdio.h>
#include <stdlib.h>
Check string length and set
string end int main(void)
{
#include <stdio.h> FILE *fp;
#include <string.h> int i;
i = 100; fclose(fp);
if(fread(&i, 2, 1, fp) != 1) {
printf("Read error occurred.\n");
exit(1);
}
printf("i is %d", i);
fclose(fp);
#include <stdio.h>
int main()
{
FILE *file;
Get string from file char string [100];
struct student student3; printf("The length of the line is: %d\n", str
len(line));
char s1[30];
float f; return (0);
scanf ("%s", s1); }
[CX]
/* overwrite the newline character in each stri
The functionality described on this ng */
reference page is aligned with the ISO C text[strlen(text)-1] = '\0';
standard. Any conflict between the substring[strlen(substring)-1] = '\0';
requirements described here and the
ISO C standard is unintentional. This int i;
for(i = 0 ; (text[i] = toupper(text[i])) ; i++);
volume of IEEE Std 1003.1-2001 defers to for(i = 0 ; (substring[i] = toupper(substring[i]
the ISO C standard. )) ; i++);
The fgets() function shall read bytes from printf("\nThe second string %s found in the fi
stream into the array pointed to by s, until n-1 rst.",((strstr(text, substring) == NULL) ? "was n
bytes are read, or a <newline> is read and ot" : "was"));
transferred to s, or an end-of-file condition is return 0;
encountered. The string is then terminated }
with a null byte.
[CX]
The fgets() function may mark the
st_atime field of the file associated with
stream for update. The st_atime field shall be
marked for update by the first successful
execution of fgetc(), fgets(), fgetwc(),
fgetws(), fread(), fscanf(), getc(), getchar(),
gets(), or scanf() using stream that returns
data not supplied by a prior call to ungetc() or
ungetwc().
RETURN VALUE
ERRORS
Refer to fgetc().