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

From: Joseph Rose <rose.joseph121yahoo.com>
Date: 2011-06-13 16:11:28
silverdr@wfmh.org, I thank you for your idea, but it doesn't seem to work.   I will just use my text adventure's input routine.  Maybe my version of cc65 is old and contains a bug.


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 Mon Jun 13 16:12:02 2011

This archive was generated by hypermail 2.1.8 : 2011-06-13 16:12:06 CEST