:: Re: [DNG] [OT] [Re: Studying C as t…
Etusivu
Poista viesti
Vastaa
Lähettäjä: Steve Litt
Päiväys:  
Vastaanottaja: dng
Aihe: Re: [DNG] [OT] [Re: Studying C as told. (For help)
On Tue, 21 Jun 2016 14:43:03 -0400
"Steven W. Scott" <codekraken@???> wrote:

> May as well toss in the assembler guy approach to the problem:
>
> char SpaceSquash()
> {
>           for (i = strlen(desc) - 1; i > 0; i--) {
>                if (desc[i-1] == ' ') {
>                    if (desc[i] == ' ') {
>                        strncpy(&desc[i], &desc[i+1],
> (strlen(desc)-i)); }
>                 }
>             }
>           return 0;
> }


This is fun.

Here's a program to take any sentence you copy and paste from an online
article onto the command line, and expands interword spacing to a
random 1 thru 5 spaces, for input into your condenser. When using my
program, note that I didn't program circuit breakers for exceeding
BIG_ENOUGH.

======================================================
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<string.h>

#define BIG_ENOUGH 1000


int main(int argc, char * argv[]){
    char buf[BIG_ENOUGH];
    char *pch = buf;
    time_t tt;
    long seed = time(&tt);
    srandom(seed);
    int i;
    for(i=1; i < argc; i++){
        int spaces = 1 + 5 * random()/RAND_MAX;
        strncpy(pch, argv[i], strlen(argv[i]));
        pch += strlen(argv[i]);
        memset(pch, ' ', spaces);
        pch += spaces;
        *pch = '\0';
    }
    printf("buf=>%s<\n", buf);
    return 0;
}
======================================================


SteveT

Steve Litt
June 2016 featured book: Troubleshooting: Why Bother?
http://www.troubleshooters.com/twb