Jump to content

handling txt-files!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
carita88

carita88

    Newbie

  • Members
  • Pip
  • 3 posts
I have txt-file and I have to check if it is in right format. something like:
-;666;2006-12-12;-;help me! (there could be more lines than one)
So, how do I check the right number of ';' and that they are in right places...??? And how I get that kind of timestamp?

#2
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
This is what you will need to do:

Open the text File
Split the text file by line breaks (\r\n or \n or \r)
Loop through each line
Split each line by ;
print the value
End Loop

Are you using Ansi C++? If so, I'll post some code.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
A lot of the answer will depend on whether you are using C or C++. C++ allows you to make use of the string class and all its power, whereas with C you'll have to code everything by hand. In C, the key will be knowing that strings are really just arrays, and you can use for loops to traverse them looking for the semi-colons.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
carita88

carita88

    Newbie

  • Members
  • Pip
  • 3 posts
using c. I will have to print whole lines and be able to handle those "values" between each ';'. Do I have to save each value to it's own array or is it better to use tables?

#5
Void

Void

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 411 posts
I don't much about splitting in C but I assume you could add the value of the string to another string util you reach a ;. Once a ; is reached you could simply print that value and start over.
Void

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Look at the string functions in C.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Well I dont know any C or so.. but this may help perhaps?
Attached source:-

Attached Files