Movatterモバイル変換


[0]ホーム

URL:


C fscanf

C Programming Tutorials

Overview of C LanguageC Language FundamentalsData Input and OutputDecision Control StatementsLoop Control StatementsFunctionsPreprocessors and Header FilesArrays and StringsPointersStructure and UnionFile Handling

Cfscanf() function reads formatted input from a file. This function is implemented in file-related programs for reading formatted data from any file specified in the program. This tutorial guides you on how to use thefscanf() function in the C program.

Syntax:

int fscanf(FILE *stream, const char *format, ...)

Its returns the number of variables that are assigned values orEOF if no assignments could be made.

Example:

int main(){    char str1[10], str2[10];    int yr;    FILE* fileName;    fileName = fopen("anything.txt", "w+");    fputs("Welcome to", fileName);    rewind(fileName);    fscanf(fileName, "%s %s %d", str1, str2, &yr);    printf("----------------------------------------------- \n");    printf("1st word %s \t", str1);    printf("2nd word  %s \t", str2);    printf("Year-Name  %d \t", yr);    fclose(fileName);    return (0);}


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

[8]ページ先頭

©2009-2025 Movatter.jp