Thread: TEXT FILE TO ASCII - newbie

  1. #16
    .
    Join Date
    Nov 2003
    Posts
    307
    [off topic slightly]
    If you're on a unix box (I can't tell positively), all of this is a done deal -written long ago.
    sed, grep, and maybe awk are your friends.
    [/off topic slightly]

  2. #17
    Registered User
    Join Date
    Oct 2004
    Posts
    8
    Please help: I am unable to run a C Program which I have written as an extension of an earlier simple program. I believe it has to do with an object file clash which I am not able to resolve. Here is the source code for my program:

    /* opens and extracts text from a file */

    #include <stdio.h>
    #include <string.h>
    #include "tfdef.h"
    #include "strdef.h"
    #define MAXSIZE 5000

    int main()
    { FILE *ifp, *ofp; /* ifp is input file pointer & ofp is output file pointer */
    char month[MAXSIZE];
    char cmonth[MAXSIZE]; /* clearance month */
    char cdate[] = ""; /* clearance month using format YYYYMM */

    ifp = fopen("form2.txt", "r"); /* open "form1.txt" for reading by assigning to ifp */
    if(ifp==NULL) {
    printf("Error: can't open file form1.txt.\n");
    exit(0);
    }

    else {
    printf("Input file opened successfully.\n");
    }

    ofp = fopen("outfile1.txt" , "w"); /* open file for output */
    if(ofp==NULL) {
    printf("Error: can't open file for output.\n");
    exit(0);
    }
    else {
    printf("Output file opened successfully .\n");
    }

    /* Here need to write function that when control string is recognized it
    creates its numeral equivalent and writes it to the ouput file - 13
    cases for control month: December 2004 to December 2005 */

    while (fgets(cmonth, MAXSIZE - 1, ifp))
    if(month == "December 2004"){
    if(srchstr(cmonth,month)) {
    cdate[1] = "200412";
    }
    }
    else
    if(month == "January 2005") {
    if(srchstr(cmonth,month)) {
    cdate[1] = "200501";
    }


    fputs(cdate, ofp);
    fclose(ifp);
    fclose(ofp);

    }
    int srchstr(STRING s, STRING str)
    {
    while (*s)
    if (compare(s, str)) /* if str is at the start of s */
    return TRUE; /* return TRUE */
    else s++; /* otherwise, go to the next position */

    return FALSE; /* string exhausted, return FALSE */
    }

    int compare(STRING s, STRING str)
    {
    while(*str)
    if (*str++ != *s++)
    return FALSE;

    return TRUE;
    }
    }

    ==============================================
    Compiling the file I specify readfile as the object file. I enter the following prompt command:

    $ gcc -Wall rfile.c -o readfile

    The attached file gcc_compile shows the results of compilation. I then execute the object file by entering the command:

    $ readfile

    - bash: readfile: command not found

  3. #18
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I am unable to run a C Program
    You're also unable to use code tags I guess.

    Also, avoid attaching proprietary document formats. .txt is the format of choice.
    If you understand what you're doing, you're not learning anything.

  4. #19
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Closed for a bump

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM