Re: [cc65] Input string routine for a line of data?

From: Joseph Rose <rose.joseph121yahoo.com>
Date: 2011-06-08 17:43:03
Maybe I need to upgrade cc65.  Thank you, silverdr@wfmh.org.pl.


From: "silverdr@wfmh.org.pl" <silverdr@wfmh.org.pl>
To: cc65@musoftware.de
Sent: Wednesday, June 8, 2011 11:32 AM
Subject: Re: [cc65] Input string routine for a line of data?


On 2011-06-08, at 14:55, Joseph Rose wrote:

> This is my latest version of the example routine:

C00l!

> printf ("Type in name of file to compress: ");
> fgets(f,17,stdin);
> putchar ('\n');
> strcat (f,",p");
> Does it work onyour system?

#include <stdio.h>
#include <string.h> 
int main()
{
    char f[20];
    printf ("Type in name of file to compress: ");
    fgets(f,17,stdin);
    putchar ('\n');
    strcat (f,",p");
    printf("\ntext = \"%s\"\n", f);
    return 0;
}

does work. Even if you probably want to strip newline from the input string first. Something like..

#include <stdio.h>
#include <string.h> 
int main()
{
    char f[20];
    char *newline;
    printf ("Type in name of file to compress: ");
    fgets(f,17,stdin);
    putchar ('\n');
    if(newline = strchr(f, '\n'))
        *newline = '\0';
    strcat (f,",p");
    printf("\ntext = \"%s\"\n", f);
    return 0;
}

-- 
SD!

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Jun 8 17:43:17 2011

This archive was generated by hypermail 2.1.8 : 2011-06-08 17:43:21 CEST