Sponsored Content
Top Forums Programming import .txt and split word into array C Post 302561153 by guidely on Monday 3rd of October 2011 10:10:58 AM
Old 10-03-2011
Code:
#include <stdio.h> 

int DisplayFile(char filename[]) 
{ 
    FILE *f; 
    int     ch;  /* int or signed char. See below. */ 
    f = fopen(filename, "r"); 
    if (f == NULL) { 
        /* Couldn't open the file. */ 
        printf("Input file not found.\n"); 
        return -1; /* Non-zero means error. */ 
    } 
    /* Display the entire file on the screen */ 
    ch = fgetc(f); 
    while (ch != EOF) 
    { 
        ch = strtok(filename, " ");
        putchar(ch);  /* Display one char on screen */ 
        ch = fgetc(f); 
    } 
    return 0; 
} 
int main(void) 
{ 
    int   result; 
    result = DisplayFile("fadata.rtf"); 
    return result; 
}

it not working

I just want split and store into array or make it variable to use to calculate other thing

Last edited by guidely; 10-03-2011 at 11:17 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies

2. Shell Programming and Scripting

Shell snip to import CSV data into BASH array

I have been trying to write a simple snip of bash shell code to import from 1 to 100 records into a BASH array. I have a CSV file that is structured like: record1,item1,item2,item3,item4,etc.,etc. .... (<= 100 items) record2,item1,item2,item3,item4,etc.,etc. .... (<= 100 items)... (5 Replies)
Discussion started by: dstrout
5 Replies

3. Shell Programming and Scripting

shellscript to read data from txt file and import to oracle db

Hi all, Help needed urgently. I am currently writing a shellscript to read data/record from a flat file (.txt) file, and import/upload the data to oracle database. The script is working fine, but it takes too long time (for 18000 records, it takes around 90 mins). I guess it takes so long... (1 Reply)
Discussion started by: robot_mas
1 Replies

4. Shell Programming and Scripting

KSH script for split a txt file

I have a problem which I would like to solve by using UNIX power and inspired minds around world. Here is the problem I have a text file and it has data as follows 1X.....................1234567890123456789T1234598765XT1 (header) 1Z01............(sub HEADER) P100001............ Q1........... (4 Replies)
Discussion started by: ask.chowhan
4 Replies

5. Shell Programming and Scripting

How to import a value from txt file

Hello, I want to give a value from a txt file to my variable at my ksh script. I`ve searched on the net and I found the command variable < file.txt but it cannot see the file. The .txt file contains two values in the first and the second line. Is there any way to give the first-line value to... (1 Reply)
Discussion started by: chris_euop
1 Replies

6. Shell Programming and Scripting

How to split this txt file into small files?

Dear shell experts, I would like to spilt a txt file into small ones. However, I did not know how to program use shell. If someone could help, it is greatly appreciated! Specifically, I supposed there is file named A.txt. The content of the file likes this: Subject run condtion ACC time... (3 Replies)
Discussion started by: psychmyluo
3 Replies

7. Windows & DOS: Issues & Discussions

SQL Server import csv or txt on a Solaris box

New to using sql server and unix, but say I have here /home/foo/file.txt Can I use some kind of process to push that .txt into a sql server? Or Is there a sql server utility that can be configured to find a unix box and go into /home/foo/file.txt and slurp it up:) Or is there any PC and... (5 Replies)
Discussion started by: sas
5 Replies

8. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

9. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

10. Shell Programming and Scripting

Array - Export/Import in global environment variables.

Hello. During startup /etc/bash.bashrc.local generates some array ..... source /.../.../system_common_general_array_env_var ..... The file system_common_general_array_env_var contains : LEAP_VERSION='42.3' ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' ... (2 Replies)
Discussion started by: jcdole
2 Replies
GETS(3) 						     Linux Programmer's Manual							   GETS(3)

NAME
fgetc, fgets, getc, getchar, gets, ungetc - input of characters and strings SYNOPSIS
#include <stdio.h> int fgetc(FILE *stream); char *fgets(char *s, int size, FILE *stream); int getc(FILE *stream); int getchar(void); char *gets(char *s); int ungetc(int c, FILE *stream); DESCRIPTION
fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once. getchar() is equivalent to getc(stdin). gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with ''. No check for buffer overrun is performed (see BUGS below). fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '' is stored after the last character in the buffer. ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed - back characters will be returned in reverse order; only one pushback is guaranteed. Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream. For non-locking counterparts, see unlocked_stdio(3). RETURN VALUE
fgetc(), getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error. gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read. ungetc() returns c on success, or EOF on error. CONFORMING TO
ANSI - C, POSIX.1 BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead. It is not advisable to mix calls to input functions from the stdio library with low - level calls to read() for the file descriptor associ- ated with the input stream; the results will be undefined and very probably not what you want. SEE ALSO
read(2), write(2), ferror(3), fopen(3), fread(3), fseek(3), puts(3), scanf(3), unlocked_stdio(3) GNU
1993-04-04 GETS(3)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy