Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(){
  4. int i, ret;
  5. char c, type;
  6. do
  7. {
  8. printf("Convert ASCII # to charactern");
  9. printf("q: Quit.n");
  10. scanf("%c", &type);
  11. /* I use the " if(type== 'n'); " a number of times. */
  12. /* I left the others out to simplify what my problem is. */
  13. if(type=='1'){
  14. printf("ASCII NUMBER -> CHAR n");
  15. printf("t Please input one ASCII code n");
  16. int ret = scanf("%d", &i);
  17. /* My aim here is to get the amount of integers the user inputs,*/
  18. /* and use that to categorize, but I think I am failing to do so. */
  19. if(ret==1){
  20. printf("t The character for ASCII code %d is -> '%c' nn", i, i);
  21. break;
  22. }
  23. else{
  24. printf("Please input one number./n/n");
  25. break;
  26. }
  27. }
  28.  
  29. }
  30. while(type=='q');
  31. return 0;
  32. /* A problem I face a lot is where the program would terminate*/
  33. /* even when the while conditions weren't met. */
  34. }
  35.  
  36. scanf("%c",type);
  37.  
  38. int ret = scanf("%d", &i);
  39.  
  40. printf("t Please input one ASCII code n");
  41. int ret = scanf("%d", &i);
  42. getchar(); //this will read the [enter] character in input buffer
  43. /* My aim here is to get the amount of integers the user inputs,*/
  44. /* and use that to categorize, but I think I am failing to do so. */
  45. if(ret==1){
  46.  
  47. char buffer[256], type;
  48. fgets( buffer, sizeof(buffer), stdin );
  49. if( sscanf( buffer, "%c", &type ) == 1 ) {
  50. // Was able to read a char from the buffer, now you can use it.
  51. }
  52. else {
  53. // Wasn't able to read a char from the buffer. handle it if required.
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement