array design

This is a discussion on array design within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I'm doing the following problem: Create an algorithm that'll accept a person's name as "lastname,firstname", and then display ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    array design

    Hey everyone,
    I'm doing the following problem:
    Create an algorithm that'll accept a person's name as "lastname,firstname", and then display the name as "first name(3spaces)lastname"
    So I was wondering if anyone had any good starting comments, I wrote this whole elaborate program until I realized I was using char as if they were able to dynamically allocate memory...yeah...so...that sucked

    I was just wondering if anyone could toss some hints of where to start (over)...thanks!

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    20
    Hmmm...

    I'd say you should probably look into strings...

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    #include<iostream>
    #include<cstring>
    using namespace std;
    
    char* get_first_name(char*);
    char* get_last_name (char*);   
    
    int main( )
    {
    
         char full_name[20], first_name[20], last_name[20];
    
         cout << "Enter last name then first name, seperated by comma: ";
    
         cin.getline(full_name, 20);
    
         strcpy(first_name, get_first_name(full_name));
    
         strcpy(last_name,   get_last_name(full_name));
    
         cout << "\nYour full name is: "; 
    
         cout << first_name << "   " << last_name;   
    
         return 0;
    
    }
    Last edited by The Brain; 07-30-2005 at 07:26 AM. Reason: correct syntax errors in variable declarations.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    char[20] full_name, first_name, last_name;
    Unless I'm mistaken, you mean . . .
    Code:
    char full_name[20], first_name[20], last_name[20];
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Lightbulb

    yesss.. i knew someone was going to catch this error.. i knew something was wierd.. didn't hit me until i got into work last night and started thinking about it.. good catch dwk.. i'll edit for correctness.
    Last edited by The Brain; 07-30-2005 at 09:50 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 10:21 PM
  5. mode of an array
    By Need Help in forum C Programming
    Replies: 15
    Last Post: 09-17-2001, 09:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21