Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(){
- int i, ret;
- char c, type;
- do
- {
- printf("Convert ASCII # to charactern");
- printf("q: Quit.n");
- scanf("%c", &type);
- /* I use the " if(type== 'n'); " a number of times. */
- /* I left the others out to simplify what my problem is. */
- if(type=='1'){
- printf("ASCII NUMBER -> CHAR n");
- printf("t Please input one ASCII code n");
- int ret = scanf("%d", &i);
- /* My aim here is to get the amount of integers the user inputs,*/
- /* and use that to categorize, but I think I am failing to do so. */
- if(ret==1){
- printf("t The character for ASCII code %d is -> '%c' nn", i, i);
- break;
- }
- else{
- printf("Please input one number./n/n");
- break;
- }
- }
- }
- while(type=='q');
- return 0;
- /* A problem I face a lot is where the program would terminate*/
- /* even when the while conditions weren't met. */
- }
- scanf("%c",type);
- int ret = scanf("%d", &i);
- printf("t Please input one ASCII code n");
- int ret = scanf("%d", &i);
- getchar(); //this will read the [enter] character in input buffer
- /* My aim here is to get the amount of integers the user inputs,*/
- /* and use that to categorize, but I think I am failing to do so. */
- if(ret==1){
- char buffer[256], type;
- fgets( buffer, sizeof(buffer), stdin );
- if( sscanf( buffer, "%c", &type ) == 1 ) {
- // Was able to read a char from the buffer, now you can use it.
- }
- else {
- // Wasn't able to read a char from the buffer. handle it if required.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement