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 */

Recommended Answers

All 7 Replies

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.

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

fstream in(file);
in.getline(char*,streamsize,char);
fstream in(file);

You're in C country :)

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;
  }
commented: get with the program -1

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.

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.