Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,121 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,760 people online right now. Registration is fast and FREE... Join Now!




what esle can i use instead of strcat?

 
Reply to this topicStart new topic

what esle can i use instead of strcat?

shahnozajon
11 Apr, 2007 - 04:02 PM
Post #1

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 13


My Contributions
CODE
/* HEADER FILES */
#include <stdio.h>
#include <conio.h>
#include <string.h>

/* The char "c1" and "c2" are initialized in order that not affect the thousands */
char *a2roman (int value, char *c1, char *c2, char *c3);

int main (void)
{
    int arabicalNumeral = 1; /* Initialization for read althought one time  */
    int result;              /* "result" store the position value           */
    char roman[15] = "";     /* "roman" contain the roman-numeral string    */

    /* This cicle allow to continue if "arabicalNumber" to be in the range */
    do
    {
        /* Clear the screen */
        clrscr();

        /* Print a message to user */
        printf ("Enter a integer in 1 to 3000 range of integers: \n\t");

        /* Read the value */
        scanf ("%d", &arabicalNumeral);
    }
    while ((arabicalNumeral < 1) || (arabicalNumeral > 3000));

    /* Obtain the value of thousands */
    if ((arabicalNumeral <= 3000) && (arabicalNumeral >= 1000))
    {
        result = arabicalNumeral / 1000;
        strcat (roman, a2roman(result, "M", " ", " "));
        arabicalNumeral -= (result * 1000);
    }

    /* Obtain the value of hundreds */
    if ((arabicalNumeral < 1000) && (arabicalNumeral >= 100))
    {
        result = arabicalNumeral / 100;
        strcat (roman, a2roman(result, "C", "D", "M"));
        arabicalNumeral -= (result * 100);
    }

    /* Obtain the value of tens */
    if ((arabicalNumeral < 100) && (arabicalNumeral >= 10))
    {
        result = arabicalNumeral / 10;
        strcat (roman, a2roman(result, "X", "L", "C"));
        arabicalNumeral -= (result * 10);
    }

    /* Obtain the value of units */
    if ((arabicalNumeral < 10) && (arabicalNumeral >= 1))
    {
        strcat (roman, a2roman(arabicalNumeral, "I", "V", "X"));
    }

    /* Display the Roman numeral */
    printf ("The Roman numeral is: \n\t%s\n\n", roman);
    printf ("\t\t      ...Press any key to exit.");
    getch();

    /* Succesfull return */
    return 0;
}

char *a2roman (int value, char *c1, char *c2, char *c3)
{
    int i;    /* "i" is the index of the iteration */
    char rRoman[15] = "";

    /* If value = 1, 2, 3 */
    if ((value >= 1) && (value <= 3))
    {
        for (i = 0; i < value; i++)
            strcat (rRoman, c1);
    }

    /* If value = 5, 6, 7, 8 */
    if ((value >= 5) && (value <= 8))
    {
        strcat (rRoman, c2);

        for (i = 0; i < (value - 5); i++)
            strcat (rRoman, c1);
    }

    /* If value = 4 */
    if (value == 4)
    {
        strcat (rRoman, c1);
        strcat (rRoman, c2);
    }

    /* If value = 9 */
    if (value == 9)
    {
        strcat (rRoman, c1);
        strcat (rRoman, c3);
    }

    return (rRoman);
}


i was wondering if there's any way to use sthn else instead of strcat in this code? any help would be appreciated
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: What Esle Can I Use Instead Of Strcat?
11 Apr, 2007 - 04:13 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
What is it you want to do? Concatenate the strings? that's what strcat() is meant for, although there is also the strncat() function. You'd have other options with a C++ string object, but you appear to programming in C. Is there a problem with the strcat() function?
User is offlineProfile CardPM
+Quote Post

shahnozajon
RE: What Esle Can I Use Instead Of Strcat?
11 Apr, 2007 - 04:19 PM
Post #3

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 13


My Contributions
QUOTE(Amadeus @ 11 Apr, 2007 - 05:13 PM) *

What is it you want to do? Concatenate the strings? that's what strcat() is meant for, although there is also the strncat() function. You'd have other options with a C++ string object, but you appear to programming in C. Is there a problem with the strcat() function?


well i got this program from someone and i understand all of it, but my professor didn't go over strcat, strcpy, strcmp or any of that. is there any other way to write this program so we don't have to use the strcat part?
User is offlineProfile CardPM
+Quote Post

GWatt
RE: What Esle Can I Use Instead Of Strcat?
11 Apr, 2007 - 04:22 PM
Post #4

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,178



Thanked: 18 times
Dream Kudos: 450
My Contributions
You could write your own. Or you could go HERE to see what those functions are all about.
User is offlineProfile CardPM
+Quote Post

shahnozajon
RE: What Esle Can I Use Instead Of Strcat?
11 Apr, 2007 - 04:31 PM
Post #5

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 13


My Contributions
QUOTE(GWatt @ 11 Apr, 2007 - 05:22 PM) *

You could write your own. Or you could go HERE to see what those functions are all about.

i could write my own but that's why i posted it up here, i was trying to find someone who knows how to convert that to sthn else. is it even possible? smile.gif
User is offlineProfile CardPM
+Quote Post

keems21
RE: What Esle Can I Use Instead Of Strcat?
11 Apr, 2007 - 10:21 PM
Post #6

D.I.C Head
Group Icon

Joined: 3 Feb, 2007
Posts: 183



Thanked: 2 times
Dream Kudos: 25
My Contributions
In C, all a string is, is an array of chars.

So take this psudocode:
CODE

char str1[20];   //pretend it already has a value
char str2[20];   //same here
char concated[40];    //where the concated string will go
int x;

for(x = 0; x < strlen(str1); x++)
  concated[x] = str1[x];  //adds the first string to concated

for(x = 0; x < strlen(str2); x++)
  concated[x + strlen(str1)] = str2[x];  //adds the second string


How about that?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:07PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month