File operations in C pgm

Thread Tools Search this Thread
Top Forums Programming File operations in C pgm
# 1  
Old 05-13-2012
Java File operations in C pgm

i am reading and writing to a a file in C language. the input file is described as follows

111 aaa descr1
222 bbb descr2
333 ccc <SPACE> {6 spaces are left after ccc i.e in 3rd column}
444 ddd descr4

when i read and write to a file, the space is not coming in the output file.

Expected output:
111aaadescr1222bbbdescr2333ccc 444ddddescr4

Can somebody help me in modifying the code?

Last edited by vkca; 05-13-2012 at 12:03 PM..
# 2  
Old 05-13-2012
Sure. Please show us the code.
# 3  
Old 05-13-2012
struct buffer {
       char data1[255];
       char data2[255];
       char data3[255];
int main(int argc, char *argv[]){
 struct buffer dat;
  char *line = NULL;
   FILE *inFilePtr;
   FILE *outFilePtr;
  inFilePtr = fopen("test.txt", "r+");
  outFilePtr = fopen("out.txt", "w+");
   while (!feof(inFilePtr)){
      fscanf(inFilePtr, "%s", &line);
      printf("%s", &line);
      fprintf(outFilePtr,"%s", &line);
 return 0;

# 4  
Old 05-13-2012
fscanf skips over blanks. Experiment with this
char tmp[80]={0x0};
while fgets(tmp, sizeof(tmp), inFilePtr)
    fprintf(outFilePtr, "%s", tmp);

# 5  
Old 05-13-2012

hi Jim,
fgets is not working. the output is same as the input

111 aaa descr1
222 bbb descr2
333 ccc <SPACE> {6 spaces are left after ccc i.e in 3rd column}
444 ddd descr4
# 6  
Old 05-14-2012
That's exactly what you asked for -- spaces in the output, just like the input.

If that's not what you want now, what do you want instead?
# 7  
Old 05-14-2012

Mr Corona688,
please read my first thread..... u will get to know what i am expecting!

i asked the output to be in this format
111aaadescr1222bbbdescr2333ccc 444ddddescr4

but my program output is coming like
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Operations

Hi Folks, Below is example of an Input data which is used, based on the last 2, 3 & 4 column, I want my first column data to be collated as shown in the output section. a,ac,tc,ic b,ac,tc,ic c,ac,tc,ic d,ac,tc,ic b,bc,tc,ic d,bc,tc,ic e,bc,tc,ic I want my output to be ... (2 Replies)
Discussion started by: nikhil jain
2 Replies

2. Shell Programming and Scripting

Operations inside a file

Hi all, i need to do a piecewise integration between this example data inside a file : 500856704.00 11536282.5600897 50496 500402784.00 11538000.3654401 -453920 500654880.00 11538000.4662785 252096 500604416.00 11539718.4330113 -50464 500907168.00 11539718.5541121 302752 500705280.00... (3 Replies)
Discussion started by: Board27
3 Replies

3. Shell Programming and Scripting

How to search and append words in the same file using unix scripting file operations

Hi , I have a file myhost.txt which contains below, localhost atrpx958 atrpx958zone nsybhost I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone. How to search the word atrpx958(which is hostname) only,... (5 Replies)
Discussion started by: gsreeni
5 Replies

4. Shell Programming and Scripting

Perform Operations on One File Conditional on Data in Another File

Hello all, I am looking for a solution to the following problem. Perl or python solutions also welcome. Given this input: And this input: I want to get this output. The rule being that if the number in the first file is < 0.9, then the corresponding two columns on... (2 Replies)
Discussion started by: hydrabane
2 Replies

5. UNIX for Advanced & Expert Users

how to check port already used in pcap pgm

hi, I am writing one packet receiving program using libpcap library. Now, I want to check port is already using or not. how to check in receiver program.. If normal program,using bind return value we can able to check the port is already using or not. but, in pcap program how can i... (1 Reply)
Discussion started by:
1 Replies

6. Shell Programming and Scripting

Unix File operations

Hi, Iam having the two files as follows: file1: ASQWEDFR09876543121234512 POIUYTREW09876512345676788 ZXCVBNMKS1209888888888888 file2: ASQWEDFR09876543121234516 0000000-90-1239--2008 8990---- CXADFGTU09876543121234789 ... (14 Replies)
Discussion started by: nivas
14 Replies

7. UNIX for Dummies Questions & Answers

Which pgm write into a file ?

Hi! I'm looking for a command/script to be able to get the program who write into a file. I've a logfile who grow up but I don't find which program write on it :eek: thanks for your support&help. .fr. (2 Replies)
Discussion started by: Franzlebord
2 Replies

8. Programming

Pgm Output is Interleaved with other pgms

Hi I have a shared object which is called from a third party tool. In my .so, I am using 'freopen(mylogfilename,"at",stderr)'. It is logging all my program output and it is also writing warning messages from the third party daemons also. How can I avoid these unwanted messages... (1 Reply)
Discussion started by: axes
1 Replies

9. UNIX for Dummies Questions & Answers

File operations

Hi I have a tab delimited file with 3 fields. I need to sort this file on the first field and remove all the records where the first field has dulplicates. For eg my file is 133|arrfdfdg|sdfdsg 234|asfsdgfs|aasdfs 133|affbfsde|dgfg When this file gets sorted I need the result to be ... (2 Replies)
Discussion started by: monks
2 Replies

10. Shell Programming and Scripting

File operations

Hi there, I want some help on scripting regarding file processing. I have a scenario in which I have 10 files. (file1.txt, file2.txt....) and they are in paricular format. I want to read these files and append some text lines at the begining of each file and write this updated contents of... (2 Replies)
Discussion started by: chiragmistry21
2 Replies
Login or Register to Ask a Question

Featured Tech Videos