Thread: Pointers and Structures

  1. #1
    Registered User mattz's Avatar
    Join Date
    Nov 2001

    Unhappy Pointers and Structures

    Hello, back again with some pointer and structure issues. I want to read in some text and the (in an already completed function) manipulate the text to be bold .
    I have been able to read in and pass the text using (string.h) library and gets function. However, I want to take that string thats read in and repoint my next statement (do you want it bold?) so I only read in text once and manipulate it.

    struct rec
    char txt[100]; /* Text variable */
    char bold[100]; /* Bold variable */
    char uline[100]; /* Underline Variable */
    char italics[100]; /* Italics Variable */

    /* prototype */

    struct rec inputA; /* Define Structures */

    /* a pointer to a structure */
    struct rec *st_ptr;

    /* Begin Phase 2 */

    st_ptr = &inputA;
    /* point the pointer to rec structure */

    printf("\nPlease Enter some text: ");
    gets( inputA.txt);


    // Process text?
    printf("\nDo you want text to be bold?[1/0] ");
    scanf("%d", &response);

    if(response == YES){
    //* Assign value of text to bold address *//

    *(st_ptr) == inputA.bold;
    puts("Text will be Bold");

    //I then call the function


    Obviously I am missing some code here, I can provide if it helps.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    > //* Assign value of text to bold address *//
    > *(st_ptr) == inputA.bold;

    Um. No. This is entirely wrong.

    First off, "==" is not an assignment operator.
    Second, if it were, you'd be assigning a value to "st_prt", not to "inputA.bold".
    Third, you can't assign string values that way.

    Read up on how to use strcpy, or it's safer companion, strncpy.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector of arrays of pointers to structures
    By Marksman in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 04:44 AM
  2. Structures, and pointers to structures
    By iloveitaly in forum C Programming
    Replies: 4
    Last Post: 03-30-2005, 06:31 PM
  3. structures with pointers to structures
    By kzar in forum C Programming
    Replies: 3
    Last Post: 11-20-2004, 09:32 AM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Freeing pointers in structures
    By jim50498 in forum C Programming
    Replies: 4
    Last Post: 03-08-2002, 12:53 PM