Like Tree2Likes
  • 1 Post By TheBigH
  • 1 Post By stahta01

Editing an array of Strings.

This is a discussion on Editing an array of Strings. within the C Programming forums, part of the General Programming Boards category; im having trouble with my program here. i'll show you my codes but its quite long. Code: typedef struct { ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    13

    Editing an array of Strings.

    im having trouble with my program here.
    i'll show you my codes but its quite long.
    Code:
    typedef struct
    {
        float         quantity,
                    calorie;
        string15    unit;
        string20    fditem;
    }calType;
    
    typedef struct
    {
        string70 step;
    }stepType;
    
    typedef struct
    {
        string50     title;
        int            serving;
        char         course;
        calType        content[20];
        stepType    steps[15];
        int            nContents;
    }structRecipeType;
    
    struct node
    {
    structRecipeType structRecipe;
    calType structcalType;
    int nUsed;
    struct node *pNext;
    struct node *pPrevious;
    struct node *pcNext;
    struct node *pcPrevious;
    };
    typedef struct node PtrType;
    typedef PtrType *ptrPointer;
    
    void mAddStep(ptrPointer *pFirst)
    {
    int x=0, i=0,ask=1,mod=1,where='\0',correct=1,n=0,ctr=0;
    int bask=1, brun=1;
    char cDump,BA;
    ptrPointer pMod;
    stepType TEMPs[15],move;
    
    
        while(mod==1)
        {
            if(ask==1)
            {
                pMod=*pFirst;
                i=0;
                clrscr();
                printf("Recipe Title: %s\n",pMod->structRecipe.title);
                printf("--------------------------------------------------\n");
                while(pMod->structRecipe.steps[i].step[0]!='\0'&&i!=20)
                {
                    printf("%d. %s\n",i+1,pMod->structRecipe.steps[i].step);
                    i++;
                }
                printf("--------------------------------------------------\n");
                printf("Enter Information: ");
                fgets(TEMPs.step,sizeof(string70),stdin);
                TEMPs.step[strlen(TEMPs.step)-1]='\0';
                printf("Enter where to insert: ");
                scanf("%d%c",&where,&cDump);
                
                
                ctr=where;
                while(pMod->structRecipe.steps[where-1].step[0]!='\0')
                {
                    strcpy(move.step,pMod->structRecipe.steps[ctr+1].step);
                    strcpy(pMod->structRecipe.steps[ctr+1].step,pMod->structRecipe.steps[ctr-1].step);
                    strcpy(pMod->structRecipe.steps[].step)
                    ctr++;
                }
                strcpy(pMod->structRecipe.steps[where-1].step,TEMPs.step);
                ask=0;
                mod=0;
            }
        }
    }
    In the main program it calls this function to edit *pFirst which is a structRecipeType, so my problem is.
    im having trouble with moving the other values in my pMod->structRecipe.steps[].step
    down 1 more value after where i insert the new value.


    Values:
    1.Step 1
    2.Step 2
    3.Step 3
    Example Input: Step 4 at number 2
    result:
    1.Step 1
    2.Step 4
    3.Step 2
    4.Step 3
    Last edited by Salem; 10-26-2011 at 10:50 PM. Reason: Moved text outside code

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    What is your question?
    quzah likes this.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,579
    Quote Originally Posted by kuletako327 View Post
    Code:
    typedef struct node PtrType;
    typedef PtrType *ptrPointer;
    I suggest adding code comments to your code.
    I suggest asking your question outside your code block.
    I think typedef of a pointer is a bad style of programming.
    I suggest posting code that can be compiled; unless you are asking a question like it gives me this error how can I fix it.
    I strongly doing only a single type task per function; mAddStep() doing I/O and insert data is a very bad design decision.

    I am guessing making a swap function might be what you want; but, this is just a guess since you code is hard to follow and real question is a toss up.

    I am also guessing this is supposed to be a link list; but, I see no allocation of memory.

    Tim S.
    Last edited by stahta01; 10-26-2011 at 08:00 PM.
    quzah likes this.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    13
    Please Disregard I already Solved it XD sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of strings in JNI
    By kiros88 in forum C Programming
    Replies: 2
    Last Post: 07-21-2010, 12:40 PM
  2. Swapping strings in an array of strings
    By dannyzimbabwe in forum C Programming
    Replies: 3
    Last Post: 03-03-2009, 11:28 AM
  3. Replies: 2
    Last Post: 04-27-2008, 03:39 AM
  4. malloc() strings VS array strings
    By Kleid-0 in forum C Programming
    Replies: 5
    Last Post: 01-10-2005, 09:26 PM
  5. writting to a folder, and editing strings
    By Dark Nemesis in forum C++ Programming
    Replies: 7
    Last Post: 08-17-2003, 11:08 AM

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