c - Populating Heap (malloc) with a string array -


I am trying to populate the pile with a string array, but when I compiled the console gave me something I did not know what I did ...

  zero spell check (four articles [4], four dictionaries []) {int i = 0; Char * tempArticle; While (article [i]! = '\ 0') {i ++; } TempArticle = malloc (i); I = 0; While (article [i]! = '\ 0') {strcpy (temp article, article [i]); } Printf ("% s", tempArticle); }  

You can use strlen for the length of the string. In addition, you are using strcpy many times. Finally, you're just copying the Null Terminator function strakpy for you it works. The Strcpy copy takes each character up to the required tap terminator in its new buffer. In other words, you do not use it to make a letter copy at a time, but at a time, a string. However, I'm not sure what the purpose of your function is at this time.

  zero spell check (four articles [4], four dictionaries []) {int i = 0; Char * tempArticle; / * While (article [i]! = '\ 0') {i ++; } * / TempArticle = malloc ((strlen (article) +1) * shapes (four)); / * I = 0; While (article [i]! = '\ 0') {strcpy (temp article, article [i]); } * / Strcpy (tempArticle, article); Printf ("% s", Temporary Articles); }  

Again, in other words, your second loop was originally trying to copy a small and small string in tempArticle buffer unless you were a Do not copy the empty string in it. (Smallest thing, another responder said that your second loop was an infinite loop because i did not grow. However, you still have mentioned other problems).

Edit

Then to answer this comment to change it to lowercase. Normally, to convert the whole string to lowercase, you will do something like this:

  chars [] = "The string."; Four * C; (C = s; * c! = '\ 0'; c ++) * c = (four) tolower (* c);  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -