Like Tree1Likes
  • 1 Post By rags_to_riches

copying columns from a text file.

This is a discussion on copying columns from a text file. within the C Programming forums, part of the General Programming Boards category; 0 down vote favorite i have a text file which looks like this : Code: Flooding refers to all water ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    2

    copying columns from a text file.

    0down votefavorite
    i have a text file which looks like this :
    Code:
    Flooding refers to all water that overflows a node, whether it ponds or not.  --------------------------------------------------------------------------                                                             Total Maximum Maximum Time of Max Flood Ponded Hours Rate Occurrence Volume Depth Node Flooded       CMS   days hr:min    10^6 ltr    Meters  --------------------------------------------------------------------------   1064 0.15 0.000 0 00 00 0.000 0.35 1065 0.25 0.078 0 00 09 0.049 0.41 1130 0.25 0.626 0 00 00 0.106 0.90 1155 0.24 0.098 0 00 07 0.073 0.61 1173 0.25 0.106 0 00 15 0.022 0.76
    i want to copy the numerical columns (no text) such that the resulting file is like as such :
    PHP Code:
    [CODE]   1064                  0.15     0.000      0  00 00       0.000      0.35   1065                  0.25     0.078      0  00 09       0.049      0.41   1130                  0.25     0.626      0  00 00       0.106      0.90   1155                  0.24     0.098      0  00 07       0.073      0.61   1173                  0.25     0.106      0  00 15       0.022      0.76[/CODE
    Till now i have managed to do this code in C :
    Code:
    #include<stdio.h>#include<stdlib.h>#include<string.h>void main(){FILE *fs,*ft;int ch;int c;fs=fopen("node.txt","r");if (fs=NULL){    puts("cannot open source file");    exit(0);}ft=fopen("new_node.txt","w");do{   ch=fgetc(fs);   if (ch=EOF)   break;   else   {    if (ch>0)    fputc(ch,ft);   }     ch++;}  while(1);  fclose(fs);  fclose(ft);  return 0;}
    The problem is that nothing is coming out of it. Can anyone help in this regard and provide a working code.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    What a sad, sad copy/paste job.
    Salem likes this.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    @alienxx - Welcome to the forum!

    Please repost your code and data, so there are newlines about every 70 places or so. Somehow, your editor removed them, making it very difficult to read.

    Copy the text and code as plain text, and paste them in, the same way -- plain text. The forum software makes the code have the right font, colors, etc, if you just surround it with code tags - which you have done correctly.
    Last edited by Adak; 12-20-2012 at 05:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-09-2011, 01:56 PM
  2. Skipping Columns in Text File
    By Vulpecula in forum C++ Programming
    Replies: 3
    Last Post: 08-08-2008, 12:10 PM
  3. text file copying incorrectly
    By IsmAvatar2 in forum C Programming
    Replies: 2
    Last Post: 05-13-2007, 11:23 AM
  4. Output Columns form a file
    By Cdrwolfe in forum Tech Board
    Replies: 2
    Last Post: 03-22-2006, 04:12 AM
  5. write to .txt file in columns
    By Seron in forum C Programming
    Replies: 4
    Last Post: 11-25-2002, 03:34 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21