Sponsored Content
Top Forums Programming Help in extracting data with command from file in C Post 302177373 by ramen_noodle on Thursday 20th of March 2008 09:46:33 PM
Old 03-20-2008
Here's another approach but it's not really pretty.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

#define BSZ 256
#define MAXLINES 5000
#define READLEN 12


int *retData(int num, int offs, char *data, int delim, void *ptr) {
int *retarr = ptr;
char *read_d;

                    if (offs >= num) {return retarr;}
                    if (retarr == NULL) {retarr = malloc(num * sizeof(int)); bzero(retarr,num);}
 
                    
                    if ( (read_d = index(data,delim)) == NULL) {
                        sscanf(data,"%d",&retarr[offs]);
                        return retarr;
                    } else {
                        sscanf(data,"%d",&retarr[offs]);
                        data = read_d + 1;
                    }

                    printf("Debug: Returning data at %p = %d at iteration %d of %d\nData = %p = %s\n",&retarr[offs],retarr[offs],offs,num,data,data);
                    return retData(num,(offs + 1),data,delim,(void *)retarr);
}

int main(int argc, char **argv) {
int x = 0, n, g;
char buf[BSZ];
int *arr[MAXLINES];
FILE *fpt;

         if (argc != 2) {printf("Please specify a filename.\n"); return 1;}
         
         if ( (fpt = fopen(argv[1],"r")) == NULL) {
            printf("Could not access filename %s.\n",argv[1]);
            return 1;
         }

         while (fgets(buf,BSZ,fpt) != NULL) {
               arr[x++] = retData(READLEN,0,buf,',',NULL);
               printf("Node pointer at %p and returned pointer = %p\n",&arr[x],arr[x]);
               if (x == (MAXLINES - 1)) {break;}
         }
         fclose(fpt);

         for (n = 0 ; n < x ; n++) {
             printf("Array node pointer at %p.\n",&arr[n]);
                for (g = 0 ; g < READLEN ; g++) {
                     printf("Values stored at %p %d = %d\n",&arr[n],n,arr[n][g]);
                }
             free(arr[n]);
          }
          return 0;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extracting recursive data file

Hi Gurus, Can awk be able to do this source file: 1|SPFE2027G1|1PFE-7000|T34801188|5066-0844| 2|T34801188|5066-0844|T35002355|5066-0845| 3|T35002355|5066-0845|T35203409|QFBR-7798| 1|SPFE2027H1|1PFE-7000|T34801198|5066-0844| 2|T34801198|5066-0844|T35002365|5066-0845| formatted into:... (1 Reply)
Discussion started by: bbeugie
1 Replies

2. Shell Programming and Scripting

Extracting Data from xml file

Hi ppl out there... Can anyone help me with the shell script to extract data from an xml file. My xml file looks like : - <servlet> <servlet-name>FrontServlet</servlet-name> <display-name>FrontServlet</display-name> ... (3 Replies)
Discussion started by: nishana
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting Data from a File

Hi I need to calculate the number of occurrences of a item in a number of files using Perl. The item appears continually throughout the files but in each case I only want to calculate it in certain blocks of the file. Example - Calculalte the number of occurrences of a 'pass' in a block of... (0 Replies)
Discussion started by: oop
0 Replies

4. Shell Programming and Scripting

extracting data from a .csv file

I have a .csv file equipment,bandtype abc,aws def,mmds ghi,umts jkl,mmds I can get the equipment from `hostname`. In my script i want to check what is the hostname. then see if it exists in the.csv file. if it does then i want to store the second parameter(bandtype) for the corresponding... (3 Replies)
Discussion started by: lassimanji
3 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. UNIX for Dummies Questions & Answers

Efficient way of extracting data from file

I am having a file, around 500 lines. which contains one letter words, two letters words,...and so on(up to 15 letter words and words are not seprated by line). I need to compare all 1 letter words with 3,4,5 and 6 letters word, all 2 letters words with 2,3,4 and 5 letters words and all 3 letters... (3 Replies)
Discussion started by: akhay_ms
3 Replies

7. UNIX for Dummies Questions & Answers

Extracting data from file

I am trying to compare the data in lines 3 & 5 to see if they match up to the '-S570' (see first code set, all proprietary information has been removed from code set) spawn telnet Trying ... Connected to CA-LOS1234-ASE-S570.cl . Escape character is '^]'. CA-LOS1234-ASE-S570 Username: ... (1 Reply)
Discussion started by: slipshft
1 Replies

8. Shell Programming and Scripting

Extracting data blocks from file

Hi all, I want to extract blocks of data from a file depending on the contents of that block. The input file(table) has several blocks each starting with 'gene' in the first column. I want to extract only those blocks which do not have the expression '_T02' in the second column. Input file ... (3 Replies)
Discussion started by: newbie83
3 Replies

9. Shell Programming and Scripting

Need Help in extracting data from XML File

Hi All My input file is an XML and it has some tags and data rows at end. Starting of data rows is <rs:data> and ending of data rows is </rs:data>. Within sample data rows (2 rows) shown below, I want to extract data value after equal to sign (until space or "/" sign). So if XML data... (7 Replies)
Discussion started by: vx04
7 Replies

10. Shell Programming and Scripting

Problem in extracting data using cut/awk command

Hi Everyone, I have a very simple problem and i am stuck in that from last 8 days. I tried many attempts, googled my query but all in vain. I have a text file named "test.txt" In that suppose i have contents like: Java: 1 Object oriented programming language 2 Concepts of Abstraction... (5 Replies)
Discussion started by: Abhijeet Anand
5 Replies
GET_DEFINED_FUNCTIONS(3)						 1						  GET_DEFINED_FUNCTIONS(3)

get_defined_functions - Returns an array of all defined functions

SYNOPSIS
array get_defined_functions (void ) DESCRIPTION
Gets an array of all defined functions. RETURN VALUES
Returns a multidimensional array containing a list of all defined functions, both built-in (internal) and user-defined. The internal func- tions will be accessible via $arr["internal"], and the user defined ones using $arr["user"] (see example below). EXAMPLES
Example #1 get_defined_functions(3) example <?php function myrow($id, $data) { return "<tr><th>$id</th><td>$data</td></tr> "; } $arr = get_defined_functions(); print_r($arr); ?> The above example will output something similar to: Array ( [internal] => Array ( [0] => zend_version [1] => func_num_args [2] => func_get_arg [3] => func_get_args [4] => strlen [5] => strcmp [6] => strncmp ... [750] => bcscale [751] => bccomp ) [user] => Array ( [0] => myrow ) ) SEE ALSO
function_exists(3), get_defined_vars(3), get_defined_constants(3), get_declared_classes(3). PHP Documentation Group GET_DEFINED_FUNCTIONS(3)
All times are GMT -4. The time now is 04:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy