hi plz help me in this topic

This is a discussion on hi plz help me in this topic within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> void main() { char temp[10]; FILE *input1 = NULL; FILE *input2 = NULL; unsigned char buffer[100], lTempData[7][20]; char ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    hi plz help me in this topic

    Code:
     
    #include<stdio.h>
    void main()
    {
    char temp[10];
    FILE *input1 = NULL;
    FILE *input2 = NULL;
    unsigned char buffer[100], lTempData[7][20];
    char *lPtr = NULL;
    int i =0;
    input1 = fopen("/u/n073313/vijay/File.txt", "rb");
    
    fread(buffer, 1,100, input1);
    {
    printf("First line %s\n",buffer);
    lPtr = strtok(buffer, ",");
    
    strncpy(lTempData[i], lPtr, strlen(lPtr));
    
    while (lPtr != NULL)
    {
    i++;
    strncpy(lTempData[i], lPtr, strlen(lPtr));
    }
    
    for (int j =0; j< 7 ; j++)
    printf("Values %s\n", lTempData[i]);
    
    int a = atol(lTempData[5]);
    int b = atol(lTempData[6]);
    
    int c = a+b;
    
    printf("Values %d %d result %d\n", a, b, c);
    sprintf(temp, "%d", c);
    input2 = fopen("File2.txt", "r");
    fwrite(c, 1, 10, input2);
    fclose(input1);
    fclose(input2);
    
    }
    
    }

    The i/p txt file is like this
    939,MUM,ord,396,2,3.0,4.0
    100,bom,nru,1009,10,4.0,6.0

    and i want to add 3.0+4.0=7.0
    i.e
    First i want to read the txt file add last two columns writing it into another txt I written the code and i run the code i am getting
    ------------------------------------
    939,MUM,ord,396,2,3.0,4.0
    100,bom,nru,1009,10,4.0,6.0

    Segmentation fault(coredump)
    ----------------------------------------------

    please help me in this

    Thanks & regards
    vijay

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,752
    Asked already, only 8 minutes earlier.
    hi i am new plz help me

    Patience is also a virtue of a programmer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Plz give some comments over this topic
    By 03005654926 in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2009, 11:35 AM
  2. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  3. hi plz help me in this topic
    By vijay85 in forum Linux Programming
    Replies: 1
    Last Post: 01-27-2009, 07:48 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 01:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:44 AM

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