Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the functions related to the Operation of C language File

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "C language file operation related function example analysis", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "c language file operation related function example analysis" it!

On the usage of fscanf function

_ Check_return_ _ CRT_INSECURE_DEPRECATE (fscanf_s) _ CRTIMP int _ _ cdecl fscanf (_ Inout_ FILE * _ File, _ In_z_ _ Scanf_format_string_ const char * _ Format,...); this is the function declaration, which takes three arguments, the first is a file pointer, and the second is a format such as "% s% d." In this way, the third is the address where the data read from the file is saved. Specific these can go to Baidu, and then I would like to talk about my understanding of this. While (! feof (fp)) {fscanf (fp, "s% d", myp.myname, & myp.socer);}

You wonder why you can read the formatting characters in the file. This is because the file pointer automatically moves down, and every time we read a line, the file pointer automatically reads down a line. Something similar is the read function. (specific technical terms may be incorrect, I hope you will point out) examples are attached below

# include#include#includestruct MyStruct {char myname [10]; int socer;}; int main () {MyStruct myp;FILE * fp = NULL;fp = fopen ("d:/data.txt", "a +"); while (! feof (fp)) {fscanf (fp, "% s% d\ n", myp.myname, & myp.socer); printf ("% s% d\ n", myp.myname, myp.socer);} printf ("% s% d\ n", myp.myname, myp.socer) Fclose (fp); system ("pause"); return 0;}

Careful students may find that the fscanf () used in my example is a little different from that written earlier.

Fscanf (fp, "% s% d", myp.myname, & myp.socer); fscanf (fp, "% s% d\ n", myp.myname, & myp.socer)

Both of them can work. Having said so much, I just want to express that the file pointer will automatically move down, which you may already know.

First of all, you have to create data.txt content in the d disk like this Zhang San 100 Li Si 99 Wang 2 60 to this, I believe you have a deeper understanding of the "c language file operation-related function analysis", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report