473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to read specific column from a file ?

I have a .txt file which contains 121 lines,now I want to read the no 20 columns from that file.How to read it.I have tried the following code.

my c.txt file look like following :

A B C D E.....AAA


Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<stdio.h>
  3. #include "conio.h"
  4. #include "string.h"
  5.  
  6.  
  7. int main()
  8. {
  9.     FILE *fp;
  10.  
  11.     char a2[500];
  12.     int i=0;
  13.  
  14.     fp=fopen("c.txt","r");
  15.  
  16.     if(fp==NULL)
  17.     {
  18.     printf("\nNot Exists\n");
  19.     exit(1);
  20.     }
  21.  
  22.  
  23. for(i=0;i<=19;i++)
  24.  
  25.        {
  26.     fscanf(fp,"%c",a2[i]);
  27.     printf("%c ",a2[i]);
  28.     }
  29.  
  30.         fclose(fp);
  31.         return 0;
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
Nov 21 '13 #1
1 8941
donbock
2,426 Expert 2GB
I suggest you read the file a line at a time. For each line, extract the desired columns. You can work on these two pieces separately:
  • Read a file a line at a time: write code that reads a line and then prints it out. This part is working when the print-out looks like the original file.
  • Extract the desired columns: parse a hard-coded text line defined inside your code (don't read any files). This part is working when you have correctly extracted the columns.
Nov 21 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Daniel Chartier | last post by:
Hello, all. I found a bit of code that lets me read an Excel file from and to a specifi range. See the code below. But what if I only want to specify the STARTING position and simply want it...
0
by: Leeor Chernov | last post by:
Hi , I am using the method: DSSap.ReadXml( XmlPath,XmlReadMode.InferSchema ); And as I expected I get an error when the xml does not matching my DataSet that contains already a schema , The...
1
by: Eran.Yasso | last post by:
Hello all, This is my first time using listview. I was looking in google for a way to write to a specific column. I have 3 columns in my list view. I want to be able to write to a specific...
0
by: Problematic coder | last post by:
Hi, I have just been asked to create an app that will import a specific column from an excel spreadsheet, something like sheet1 columnD or a column with the first row with a value of 'ID'...
2
by: chikhalepankaj | last post by:
hi guys, I hv problem in reading data from text file. I want to read data in column wise from the table shown as below Module Ad Di Do 4011 1 2 ...
6
by: cooldisk | last post by:
Is it possible at all to read a binary file larger than 2GB on a 32- bit system? I tried the following: #include <iostream> #include <fstream> using namespace std; int main(int argc, char...
6
convexcube
by: convexcube | last post by:
After searching the web for a solution to total a specific column in a list box and not finding it, I came up with this: Dim varTotal As Currency Dim varRow As Integer For varRow = 1 To...
7
by: cesco | last post by:
Hi, I have a file containing four columns of data separated by tabs (\t) and I'd like to read a specific column from it (say the third). Is there any simple way to do this in Python? I've...
7
by: emokoena | last post by:
I have created a list and would like to read specific items in it, I only can read 1 import cPickle, sys, shelve ## open file that stores scores choice = None employees = while...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.