• 0

[C] File operations, word search etc


Question

I am working in C on a text file that contains METAR data.

I would like to count how many entries file contains and still I don't know where to start and how to go through.

Counting lines is out of option, as METAR files may contain some additional 'commented' header data, so my first thought was to count all "METAR"s as in every entry there is just one. And still there is a problem of this commented header - who knows if someone didn't put some "METAR" in there?

Still, I do not know how, C is a new area for me.

There is a link to METAR on wikipedia: METAR

and some of my sample file:

##########################################################
# Query made at 11/09/2009 14:49:47 UTC
# Time interval: from 11/01/2009 14:00  to 11/09/2009 14:00  UTC
##########################################################

#
#*Some commented stuff*
#

###################################
#  METAR/SPECI from EPGD
###################################
200911091400 METAR EPGD 091400Z 09009KT 0800 R29/1600 -RA FG VV003 05/05
						Q1011=
200911091330 METAR EPGD 091330Z 10012KT 1000 R29/1800 -RA BR VV002 05/05
						Q1011=
200911091300 METAR EPGD 091300Z 10012KT 1600 -RA BR OVC001 05/04 Q1011=
200911091230 METAR EPGD 091230Z 09011KT 1600 -RA BR BKN001 05/04 Q1011=
200911091200 METAR EPGD 091200Z 09012KT 1500 -RA BR BKN001 05/04 Q1011=
200911091130 METAR EPGD 091130Z 09012KT 2000 -RA BR BKN001 05/04 Q1012=
200911091100 METAR EPGD 091100Z 09013KT 2000 -DZ BR BKN001 05/04 Q1012=
200911091030 METAR EPGD 091030Z 09013KT 1200 -RADZ BR SCT001 BKN002 05/04
						Q1012=

And as you can see there might be some problems

Maybe counting "=" is a bright idea?

Do you have any ideas?

Any help is appreciated.

Link to comment
https://www.neowin.net/forum/topic/860548-c-file-operations-word-search-etc/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Well, first of all you'd need to use the stdio.h header and youd use the fscanf fucntion, here's a good reference to it: http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/

This is assuming you already have your file Handler created.

  • 0

Changed my mind.

The code that have isn't good for file reading.

But I have gone through string search so part of work is done ;)

I hope this is my last question in this case :what is the best way to insert data to array line-by-line?

  • 0
Changed my mind.

The code that have isn't good for file reading.

But I have gone through string search so part of work is done ;)

I hope this is my last question in this case :what is the best way to insert data to array line-by-line?

Linked list or hashtable with fgets.

  • 0
Just figured it out by myself.

I knew fgets, but I didnt know how to get the next line - I feel like an idiot know, it was that simple, it goes forward by itself with next call... :)

It'll only go to the next line if you read enough characters to get to the '\n' at the end of the line, which you're right, it does in normal operation. All depends on how many characters you want to read.

  • 0

Now I would like to read a wind strength from each record.

200911091200 METAR EPGD 091200Z 09012KT 1500 -RA BR BKN001 05/04 Q1011=

This is in bold. First 3 digits are the wind direction, next 2 is the strenght, KT is shortcut for knots.

I guess that it is possible to search each record for "KT" (function returning position in strong - there is sth like that?) and read 2 places before.

This is my theory, I am now looking for proper functions. Is this good? Please, advice :)

Edited by Karwowski
  • 0

Maybe not the best way - i treat string as an array and I check each index if it equals K, if the next equals T, two previous indexes must point the strenght of wind. :)

Maybe not the best, but it works :)

Thanks for all replies :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The reviews you refer to mean nothing. Where there is no journalism there is no reason to call the gaming media's opinion pieces "reviews". For GP games there is indeed a metric for success - increasing subscriptions. Which turns in revenue. The only circumstance in which subs do not rise when great is being released is a Game Pass system where the company is close to fully saturated with customers in a subscription. However, in that case as the theory goes you spend aplenty in all kind of games - from shady live service cash cows and customer offending agitprop crap in purple colours to robust and entertaining single player games. And keep a solid level of profitability. Ignoring the simply innocuous but mid games MGS has released primarily of the second kind.
    • Report: Microsoft to use AWS to help GitHub deal with a major surge in demand by Pradeep Viswanathan Thanks to the surge of coding AI agents, GitHub's usage has skyrocketed over the past 12 months. To meet this demand, GitHub started with a plan in October 2025 to increase capacity by 10x. However, by early this year, the company realized that it needed 30x scale. This rapid growth has caused severe strain on the platform's reliability, resulting in several small outages over the past few months. In April, GitHub published a long blog post explaining the steps it is taking to resolve these reliability issues. In the post, the company also confirmed that it is working toward a multi-cloud architecture for better resilience. Today, Business Insider reported that GitHub is turning to Amazon Web Services to help deal with a major surge in AI-driven coding activity. It is important to note that GitHub is still in the process of moving completely to the Azure cloud. The current plan is to move the platform fully to Azure by 2027 so that it can scale better as per developer demand. Therefore, the current decision to utilize AWS might be part of a short-term plan to meet immediate demand. A Microsoft spokesperson confirmed that GitHub is using multiple cloud providers with the following statement: For Microsoft, the decision highlights the operational pressure behind the AI boom. GitHub has to stay reliable for developers at a time when rivals such as Codex, Cursor, Claude Code, and other AI coding tools are gaining attention. And the decision to use AWS for computing capacity seems practical given the circumstances.
    • It's growing on me, however, your right, it make better usability sense if the tabs were bellow the address bar.
    • Qwen 3.6 is better value per dollar, and you can run it locally for free.
    • I don't believe them that anyone using threads, at least meaningfully. It's the same thing for Facebook, people just don't engage with Meta platforms like they are thinking. This isn't 2006.
  • Recent Achievements

    • Reacting Well
      Dys Topia earned a badge
      Reacting Well
    • Conversation Starter
      NovaEdgeX earned a badge
      Conversation Starter
    • One Year In
      Console General earned a badge
      One Year In
    • Week One Done
      Twozo Technologies earned a badge
      Week One Done
    • One Month Later
      Twozo Technologies earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      517
    2. 2
      +Edouard
      182
    3. 3
      PsYcHoKiLLa
      106
    4. 4
      Steven P.
      88
    5. 5
      ATLien_0
      68
  • Tell a friend

    Love Neowin? Tell a friend!