Hi all
What i would like to know is best shown with an example.
The user is about to save a file. The user types in "file1" as the files name. now with that I want to add a .dg onto the end of it. How would I do this?
Hi all
What i would like to know is best shown with an example.
The user is about to save a file. The user types in "file1" as the files name. now with that I want to add a .dg onto the end of it. How would I do this?
use strcat()
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Code:#include <stdio.h> #include <string.h> int main() { char file_name[1024]; /* Read the file */ printf( "Enter a file name (no extension): " ); fgets( file_name, 1024, stdin ); file_name[strcspn( file_name, "\n" )] = '\0'; /* Append the extension */ strcat( file_name, ".dg" ); /* Check that it worked right */ printf( "%s\n", file_name ); return 0; }
Processing error: Stupidity detected.
------------------------------
Dr. Bebop
Windows XP Professional Ed.
Microsoft Visual Studio 6
Nice one. Got that from Hammer?Originally posted by Dr. Bebop
Code:file_name[strcspn( file_name, "\n" )] = '\0';
Yep, it makes for cleaner looking code.
Processing error: Stupidity detected.
------------------------------
Dr. Bebop
Windows XP Professional Ed.
Microsoft Visual Studio 6
Yep got it working thanks
>>Nice one. Got that from Hammer?
Glad to see the code is being used But I can't and won't take the credit for this one liner. I first saw it used by Prelude, and thought the same as Dr Bebop.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]