Reading in file extension from user input

Posted on 2006-05-15
Last Modified: 2010-04-01
Currently I have.

char *baseDir=".\\*."

what I want to do it be able to take a user input of variable length and add it to the end of the char.  I've tried strcpy and couple other ways.  Even tried reading in the users input as a char and just doig a for loop to add to the end.  I would appreciate any help.

Question by:lightspd
    LVL 49

    Accepted Solution


    you need a buffer, and not just a pointer to the existing string literal:

    char szBuf[200];

    strcpy( szBuf, baseDir );
    strcat( szBuf, szNewInputFromUser );

    now szBuff will contain the original value plus the input.

    -- Dan

    Author Comment

    Thanks worked great.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now