simple string problem.

This is a discussion on simple string problem. within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <string.h> struct Family{ char brother_name[31]; }; int main(void){ struct Family family; printf("Brother name: \n"); ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    81

    simple string problem.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    struct Family{
    	char brother_name[31];
    };
    
    int main(void){
    	struct Family family;
    	printf("Brother name: \n");
    
    	scanf("%s", family brother_name);
    
    	printf("%s", family brother_name);
            return 0;
    }
    i want to read the brother_name and print it. can anyone help?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    	scanf("%s", family.brother_name);
    	printf("%s", family.brother_name);
    If family were a pointer, this would be:
    Code:
    	scanf("%s", family->brother_name);
    	printf("%s", family->brother_name);
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    963
    family.brother_name

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  3. C/C++ String Problem.
    By Jaken Veina in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2005, 10:11 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM

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