copy string into another string - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


copy string into another string

Anago_PeeAnago_Pee Posts: 1Member
Hey guys am a beginner in C++ and has this as an assignment i really need your help to make my marks.

1. Write a program that will reverse an accepted string and copy it into another string.

2. write a program to accept and display the amount outstanding for 10 customers. the amount outstanding should be displayed in an ascending order.


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    The string is an array, so it can be indexed as an array. And indexes begin with zero, not with one as in FORTRAN:

    char s [] = "HE'S DEAD, JIM.";

    char c1 = s[0]; [color=Green]// c1 now will contain a character 'H'.[/color]
    char c2 = s[3]; [color=Green]// c2 now will contain a character 'S'.[/color]
    [color=Blue]Now, using that fact, you can reverse a string AND copy it in one loop:[/color]
    char destination [32];
    char source [32]; [color=Green]// input that string from user (scanf,gets, etc.)[/color]
    int iSrc, iDest;
    // Find the end of the source string
    iSrc = 0;
    while (source [iSrc] != 0) iSrc++;
    // Now copy characters in reverse order
    iDest = 0;
    while (iSrc > 0)
    destination [iDest++] = source [[color=Purple]--iSrc[/color]];
    // Put terminating zero into destination string
    destination [iDest] = 0;
    [color=Blue]Now, since I did your homework - you have a new one: find out why [color=Purple]purple[/color] text says "--iSrc" and not "iSrc--"?

    For sorting items - use the bubble sort:
Sign In or Register to comment.