Thread: Foreign characters

  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18

    Foreign characters

    Hello! I was wondering how to define a foreign character? Is there some escape character for that? For example: i'm looping through my file, and when some character equals 'c', i would like to write it as 'č' (if you can see that character):

    Code:
    int myChar;
    FILE myFlow;
    
        //opening file and looping until EOF
    
            if(myChar=='c'){
                myChar='č';
                putc(myChar,myFlow);
            }
    Nothing happens. Where am i going wrong?

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Look up how to create and display Unicode characters. It is obvious the character you're trying to display is not in ASCII. Either that or wait till someone who knows how to do that comes along...
    Last edited by Happy_Reaper; 08-28-2006 at 05:21 PM.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You might try printing the character by using the ASCII code for it. For example,
    Code:
    myChar=140;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I don't believe that would work as that character does not have an ASCII code.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It may, under the OP's system. (In Linux there's something like that.) In any case, it would be an extended character and non-portable.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    It's working. myChar=232... However, there's a new problem. I have declared myFlow like this:

    Code:
    FILE *myFlow;
        myFlow=fopen("test.txt","r");
    
           //and when i use putc, nothing happens
               putc(myChar,myFlow);
    Does "r" have to do something with it?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You might have to open the file in binary mode ("rb"). I don't know if you can write extended characters to a text file.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    Nothing happens... 'c' stays 'c'... even if i use a standard character (for example 'a'). It's not writing into the file. Where am i going wrong?

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    *slaps head* "r" is read mode. You can't write to a file opened in that mode. Open the file in a write mode, such as "w" (file erased for new data) or maybe "a" (append, new data at the end of the file).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    This is what i'm using:

    Code:
    int myChar;
    FILE *myFlow;
    	myFlow=fopen("test.txt","w");
    		while((myChar=getc(myFlow))!=EOF){
    			myChar='a';  //for example, i would like to rewrite every character with 'a'
    				putc(myChar,myFlow);
    		}
    			fclose(myFlow);
    I have also tried with "a" and "rb". With "w", the file is empty, with "a" and "rb", nothing happens. How to do this right? Ohh... i forgot to mention... i'm totally new to C

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can't read (getc()) from a file opened for writing; and you can't write (putc()) to a file opened for reading. Try "r+" or "a+" ("w+" would truncuate the file).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    Thank you dwks! How stupid of me... all i needed was 2 FILE flows.

  13. #13
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Actually, I think that dwks was suggesting that you creat a FILE stream for BOTH reading and writing. That's what he meant by trying "r+" or "a+".
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  14. #14
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    I understood that, but cannot make it work. I have tried "r+" and "a+" but nothing happened. I have made it work with 2 flows ("r" and "w").

    This was actually for LaTeX (if you're familiar)... i need to read some special characters:

    ''c is č
    ''z is ž

    ...and so on. Now... i just have a "quicky" I'm reading from for example "test.txt" and writing to "testTmp.txt". How can i now, when proccess is completed, delete "test.txt" and rename "testTmp.txt" to "test.txt"... so transformed file will have the same name as original one. Am i making any sence?

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, use the rename() function to rename a file. (The behaviour is undefined if the target file already exists, so use remove() to delete the target file first.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  4. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM