Hi all,
I would like to make program reading 300 lines form a file with 24 columns.
the 24th column has an integer from 1 to 24, while the others columns are strings.

I want to summarize in seperate files this (last) column

For example,
assdsd, sdsds, asdasda, asda ,asdad, asdsad, ...., 1
hfghhghghghg,ghgh,gh,gh,g,hg,hg,h,gh,g,hg,hg, ... ,2
rtrtrtr ,rt r,t r, t,r,t r,t ,r t,r ,t ,r , r,t r,.... ,1

File1.txt
assdsd, sdsds, asdasda, asda ,asdad, asdsad, ...., 1
rtrtrtr ,rt r,t r, t,r,t r,t ,r t,r ,t ,r , r,t r,.... ,1

File2.txt
hfghhghghghg,ghgh,gh,gh,g,hg,hg,h,gh,g,hg,hg, ... ,2

Could you help me do it please ??

Easiest C version, guaranteed. Probably won't work under Windows though.

#include <stdio.h>
#include <stdlib.h>

char const * const lines[] = {
    "my %files;\n",
    "while(<>) {\n",
    "   my($index) = /(\\d+)$/;\n",
    "   $files{$index} .= $_;\n",
    "}\n",
    "for(keys %files) {\n",
    "   open OUTPUT, '>', \"File$_.txt\";\n",
    "   print OUTPUT $files{$_};\n",
    "   close OUTPUT;\n",
    "}\n",
    0
};

int main(void)
{
    FILE *script;
    char const * const *p;
    script = fopen("summarize.pl", "w");
    for (p = lines; *p; p++) {
        fputs(*p, script);
    }
    fclose(script);
    return system("perl summarize.pl");
}
commented: nice one ))) +2

Besides the joke above, the rules of this forum require to give evidence of trying to solve the problem yourself. So go ahead and post your code and errors you are encountering.

Thanks for your answer but How can I run this ?
And what is the meaning of command

return system("perl summarize.pl");

It runs the Perl language program writen to file by the C program if you have Perl installed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.