0

hi
i want to get character like 'a','c','b' etc as input from user and before geting the character first i need to get how many character should be entered if it is 5 then i will get 5 times input as character from user.and i want to asign some value to these character 'a'=10,'c'=8 'b'=9 etc ... plz help me

2
Contributors
1
Reply
24
Views
3 Years
Discussion Span
Last Post by sunktugg
0

Your question is a little bit too vague to understand.

This snippet will read an arbitrary number of characters from the user (without feedback) and store them in memory.

It will then proceed to print the numerical representation of these characters back to the screen. These numbers correspond to each characters decimal value in the ASCII table, see http://www.asciitable.com/

The part of "assigning some value" I am unable to comprehend.

#include <stdio.h>
#include <stdlib.h>

void main() {
  unsigned num_chars = 5, n;
  // create temporary buffer
  char *buf = malloc(num_chars), *p_buf = buf;
  // read characters from user
  for(n = 0; n < num_chars; n++) *p_buf++ = getch();
  // print back numbers
  for(n = 0; n < num_chars; n++) printf("buf[%i]=%i\n", n, buf[n]);
  // free temporary buffer (important)
  free(buf);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.