Thread: C language help ask

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    Unhappy C language help ask

    I need to select and print one from a group of several texts, and var_name is constructed in a separate subroutine, so it is the name of the choosen text variable (var_name in this case).
    Trying to explain widely, this is the code with more details:

    Code:
    #include <stdio.h>
    
    char var_name[9];
    char* fsubroutine (pto_cel pcpto);
    
    int main()
    {
    char *chNepC01 = "01blablablsblablablablsblablablablsblablblblaaabla0101010101.\n";
    char *chNepC02 = "02blablablsblablablablsblablablablsblablblblaaabla0202020202.\n";
    char *chNepC03 = "03blablablsblablablablsblablablablsblablblblaaabla0303030303.\n";
    ...
    char *chNepC0N = "0Nblablablsblablablablsblablablablsblablblblaaabla0N0N0N0N0N.\n";
    /* fsubroutine(sol) = var_name could be "chNepC01", "chNepC02", "chNepC03"...  "chNepC0N" */
    
    	fsubroutine(sol); /* this is a string */
    	printf("%s\n", fsubroutine(sol)); /* I want to print the text, but prints the NAME of var_name */
    
    	or...
    
    	fsubroutine(sol); /* this is a string */
    	printf("%s\n", var_name); /* I want to print the text, but prints the NAME of var_name */
    
    	return 0;
    }
    
    char* fsubroutine(pto_cel pcpto) /* constucts the string "var_name" depending of some parameters */
    {
    ...
    ...
    	return var_name; 
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    why not create array of strings and pass index of string you want to print?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Which language?
    By Halfdeck in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 09-14-2006, 06:44 PM
  2. Language - When To Use What?
    By tjinr in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 08-06-2006, 02:04 AM
  3. What's the Difference Between a Programming Language and a Scripting Language?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-15-2005, 04:46 PM
  4. C Language And A Scripting Language
    By DarkSpy in forum C Programming
    Replies: 9
    Last Post: 06-26-2003, 08:05 AM
  5. Computer Language VS Spoken Language
    By Isometric in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 02-04-2002, 03:47 PM