Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. String mystr = "";
  2. String original = "aaabb";
  3.  
  4. char last = original.charAt(0);
  5. for (int i = 1; i < original.length(); i++) {
  6. // Some code not relevant
  7. mystr += last + "" + count; // Here is my doubt.
  8. }
  9.  
  10. char mystr[1024];
  11. char * str = "abcdef";
  12. char c = str[1]; // will get 'b'
  13. int int_num = 100;
  14. sprintf(mystr, "%s%c%d", str, c, int_num);
  15.  
  16. "abcdefb100"
  17.  
  18. strcat(mystr, "xyz"); // now it is "abcdefb100xyz"
  19.  
  20. char mystr[1024]; // Assuming the maximum string you will need is 1024 including the terminating zero
  21.  
  22. char lastString[2];
  23. lastString[0] = last; // Set the current character from the for loop
  24. lastString[1] = ''; // Set the null terminator
  25.  
  26. char countString[32];
  27. itoa (count, countString, 10); // Convert count to decimal ascii string
  28.  
  29. strcat(mystr, lastString);
  30. strcat(mystr, countString);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement