Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Challange VFP: specify Text Length
Message
From
25/04/2002 03:24:01
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00648876
Message ID:
00649012
Views:
12
Hi!

This code will work way too slow in VFP. VFP is interpreter, so it is hard to do a character-to-character processing ofr text because it is slow. That is why there are a lot of string functions in VFP that simplify many things greatly, and make life easier ;)

If there are less than 65000 records, you can use ALINES() function to quickly and easy put each line of text into the separate array element. Then just loop through array till ALEN() of that array, do anything you want with string length in array element, and write back into the file...


Hope this helps.

>Needed,
>A way to mandate an input text file at a specified record length!
>C code works well ...
>
>#include <stdio.h>
>main(int argc, char * argv[])
>{
>        int c;
>        int cr=0x0d;
>        int lf=0d0a;
>        FILE *in, *out;
>        printf("argument count: %d",argc);
>        if ( argc < 4 ) { puts("Usage: setrec.exe (number of bytes for each record) (input file) (output file)"); }
>        printf("operation beginning on: %s->%s\n",argv[2],argv[3]);
>        in = fopen(argv[2], "rb");
>        if ( in == NULL ) { printf("Could not open input file,\nUsage: setrec.exe (number of bytes for each record) (input file) (output file)"); }
>        out = fopen(argv[3], "wb");
>        if ( out == NULL ) { printf("Could not open output file,\nUsage: setrec.exe (number of bytes for each record) (input file) (output file)"); }
>        for (int count=1; c=fgetc(in)!=EOF ; count++)
>        {
>          if ( count==(argv[1])) /* if bytes read is same as expected. */
>          {
>            fputc(c,out);
>            fputc(cr,out);
>            fputc(lf,out);
>            count=-1;
>          }
>          else
>          {
>            if (c==cr || c==lf)
>            {
>              count=0;
>            }
>            else
>            {
>              fputc(c,out);
>            } /* end of inner if else loop */
>          } /* end of if else loop */
>        } /* end of for loop */
>   fclose(in);
>   fclose(out);
>   printf("operation completed on: %s->%s\n",argv[2],argv[3]);
>}
>
>
>Now lets do it in VFP ...
>
>Thanx in advance
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform