0

how would i be able to seperate the text inside a file into the lines they are in?

eg:

char *lines;
lines = seperate_into_lines(a_file); /* not a function */
4
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by caut_baia
0

Use a 2D char array to hold the lines. This works best when you know roughly how many lines and how many characters in each line. Then use fgets to read them into the array one by one.

0

why you don't create a counter that is incremented on every \n and read all the characters in the file?

-1

sorry about that..

#include <iostream>
#include <fstream>
using namespace std;

int main ()
  {
    char *asd=new char[100];
    ifstream in("file.txt");
    in.getline(asd,100,'d');
    cout << asd;
    delete [] asd;
  }
Votes + Comments
get with the program
0

I think you missed my point. Now you have given an entire program in C++. That doesn't help someone with their C problem at all.

0

sorry again .. i'm new arround here. Is this about using cout instead of printf and fstream instead of sstream? ooh .. and malloc instead of new.. sorry yeah i see your point :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.