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

From: <silverdr1wfmh.org.pl>
Date: 2011-06-08 17:32:44
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.
Received on Wed Jun 8 17:32:55 2011

This archive was generated by hypermail 2.1.8 : 2011-06-08 17:32:58 CEST