Thread: Problems with array of strings

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Problem with ANSI is that the extended set isn't standard. It may look like russian on your computer, but it's not going to do so on everybody else's computer.
    Which is, at least partially, why unicode exists today.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    I need to set char set Latin 4, it's also called ISO-8859-4, but i still can't find anything, explaning how to deal with that.

  3. #18
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Quote Originally Posted by Elysia View Post
    Problem with ANSI is that the extended set isn't standard. It may look like russian on your computer, but it's not going to do so on everybody else's computer.
    Which is, at least partially, why unicode exists today.
    Yes, you'r right. But it would be enough for me to display it correctly on my computer
    Last edited by CactusC; 03-17-2008 at 02:37 AM.

  4. #19
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,786
    Quote Originally Posted by CactusC View Post
    I need to set char set Latin 4, it's also called ISO-8859-4, but i still can't find anything, explaning how to deal with that.
    First maybe try this http://www.russianlocalization.com/Texts/Encoding.htm
    To see if you can see text displayed in the specified encoding?

    PS. Also note they are metntioning ISO 8859-5 not 4
    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

  5. #20
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Quote Originally Posted by vart View Post
    First maybe try this http://www.russianlocalization.com/Texts/Encoding.htm
    To see if you can see text displayed in the specified encoding?

    PS. Also note they are metntioning ISO 8859-5 not 4
    Yes, I've already tested that, I can't see russian symbols correctly, that's why I have chosen the othe char set ISO-8859-4, which is displayed correctly in my computer.

  6. #21
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Also I wanted to ask how to print these strings, because every try computer writes me 'runtime error'

    Code:
    #include <stdio.h>
    
    int main () {
    
    	char string[100][3];
    	int i, j;
    	    j=0;
    	while (j<4)
    	         {fgets(string[j], sizeof string[j], stdin);
    	           for(i=0;i<3;i++)
    		{if(string[j][i]=='\n')
    		     {string[j][i]='\0';
    	                        j+=1; break;}}
            		 }
    	return(0);

  7. #22
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,786
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main () 
    {
    	char string[3][100];
    	int j;
    	for(j=0;j<3;j++)
    	{
    		char* p;
    		fgets(string[j], sizeof string[j], stdin);
    		p = strchr(string[j],'\n');
    		if(p) *p = '\0';
    	}
    
    	for(j=0;j<3;j++)
    	{
    		printf("String number &#37;d: \"%s\"\n", j, string[j]);
    	}
    	return 0;
    }
    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

  8. #23
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Thanks a lot The problem was that I haven't included string.h Thank's very much

  9. #24
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Hello again. Could anyone help me to find mistakes why this programs prints out only the lats string.

    Code:
    #include <stdio.h>
    #include <string.h>
    #define SIZE 124
    
    int main ()
    {
    	char *string[3];
    	char buf[SIZE], input[SIZE];
    	int j, num;
    	for(j=0;j<3;j++)
    	    {
    	       printf("\nPlease input string number &#37;d: ",j+1);
    	       fgets(input, SIZE, stdin);
    	       num = sscanf(input, "%s", &buf);
    	       if (num==1)
    		string[j] = buf; 
    	      else printf("error");
    	    }
    
    	for(j=0;j<3;j++)
    	    printf("%s\n",string[j]);
    	return 0;
    	}
    Last edited by CactusC; 03-18-2008 at 12:57 PM.

  10. #25
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Code:
    	for(j=0;j<3;j++)
    	    printf("&#37;s\n",string[0]);
    Erm, maybe your problem is here.

  11. #26
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Quote Originally Posted by mike_g View Post
    Code:
    	for(j=0;j<3;j++)
    	    printf("&#37;s\n",string[j]);
    Erm, maybe your problem is here.

    Oh, sorry, I've forrgotten to change, i was trying to print the first string, but it is like the third one.

    I have founded the mistake
    Last edited by CactusC; 03-18-2008 at 01:32 PM.

  12. #27
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Could anyone explain me why this program prints out
    "Enter string 0"
    "Enter string 1"
    at one time and doesn't read the string[0][100] ?


    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main () 
    {
    	char string[3][100];
    	int j;
    	for(j=0;j<3;j++)
    	{
    		char* p;
                                    printf("Enter string &#37;d",j);
    		fgets(string[j], sizeof string[j], stdin);
    		p = strchr(string[j],'\n');
    		if(p) *p = '\0';
    	}
    
    	for(j=0;j<3;j++)
    	{
    		printf("String number %d: \"%s\"\n", j, string[j]);
    	}
    	return 0;
    }

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have no explanation to that - is that the entire program, or is that "reduced", and if it is reduced, does it actually show the problem in reduced form. My instinct tells me that you have a scanf() before the fgets() that leaves a newline in the input buffer.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #29
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,786
    you also need to add fflush(stdout) between
    printf and fgets
    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

  15. #30
    Registered User
    Join Date
    Mar 2008
    Posts
    21
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Worksafe Array of Strings
    By Hawkin in forum C Programming
    Replies: 4
    Last Post: 03-28-2008, 11:00 PM
  2. Build an array of strings dynamically
    By Nazgulled in forum C Programming
    Replies: 29
    Last Post: 04-07-2007, 09:35 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  5. Array of strings in C
    By szill in forum C Programming
    Replies: 10
    Last Post: 02-22-2005, 05:03 PM