Thursday 28 June 2018

C Language Welcome To C!!

Hackerrank solution
C
Language
Welcome To C!!
 


Objective
This challenge will help you to learn how to take a character, a string and a sentence as input in C.
To take a single character as input, you can use scanf("%c", &ch ); and printf("%c", ch) writes a character specified by the argument char to stdout
char ch;
scanf("%c", &ch);
printf("%c", ch);
This piece of code prints the character .
You can take a string as input in C using scanf(“%s”, s). But, it accepts string only until it finds the first space.
In order to take a line as input, you can use scanf("%[^\n]%*c", s); where is defined as char s[MAX_LEN] where is the maximum size of . Here, [] is the scanset character. ^\n stands for taking input until a newline isn't encountered. Then, with this %*c, it reads the newline character and here, the used * indicates that this newline character is discarded.

C
Language
Welcome To C!!
 

int main() 
{
char a,b[10],c[10];
    scanf("%c",&a);
  scanf("%s",b);
    scanf("\n");
  scanf("%[^\n]%*c",c);
    
    printf("%c\n", a);
    printf("%s\n", b);
    printf("%s", c);
    return 0;
}

Wednesday 22 November 2017

STRING REVERSE IN 8086

name "revstr"
assume cs:code,ds:data
DATA SEGMENT
   STR1 DB 'HELLO'
   LEN EQU $-STR1
   STR2 DB 20 DUP(0)
DATA ENDS
CODE SEGMENT
   ASSUME CS:CODE,DS:DATA,ES:DATA
   START: MOV AX,DATA
          MOV DS,AX
          MOV ES,AX
          LEA SI,STR1
          MOV DI,STR2+LEN-1
          MOV CX,LEN
      UP: CLD
          LODSB
          STD
          STOSB
          LOOP UP
          MOV AH,4CH
          INT 21H
CODE ENDS
END START