Thread: simple string problem.

  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
    Make Fortran great again Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    1,400
    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, 05:05 AM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  3. C/C++ String Problem.
    By Jaken Veina in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2005, 11:11 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
Website Security Test