Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char line[1024] = { 0 };
char extra[256] = { 0 };
char path[256] = { 0 };
printf("enter dir name: ");
fgets(line, 1024, stdin);
strncpy( path, line, 255 ); // Copy maximum of 255 characters from line to path
path[ strlen( path ) - 1 ] = '\0'; // Replace newline character with NULL character
// I am unsure if the above line of code is very good practice, even though it works.
printf("%s\n\n", path );
return 0;
}
The above will work, though as I mentioned in the comments, I don't know what our strict brothers here will think about my newline hack.
[EDIT]
Holy crap, I missed one big error you made. Your call to fgets is allowing 1024 bytes to be read into a buffer (line[]) which is only 256 bytes - BAD! If the user enters more than 256 characters, you enter undefined land - you don't want to go there. :P