Showing posts with label Level. Show all posts
Showing posts with label Level. Show all posts

C Program low level strcpy

How to write a C Program low level strcpy in C Programming Language ?


This C Program low level strcpy. Wipe the string first
     -This is so that you don't end up with "Hello" mutating to something like "Hello5" if dest is e.g. "098765".

Solution:

  1. void copy_string(char *src, char *dest){
  2.     char *ps = src,
  3.          *pd = dest;
  4.  
  5.     /* Wipe the string first
  6.      * This is so that you don't end up with "Hello" mutating to
  7.      * something like "Hello5" if dest is e.g. "098765"
  8.      */
  9.     while(*pd){
  10.         *pd = 0;
  11.         pd++;
  12.     }
  13.     /* Reset pd */
  14.     pd = dest;
  15.  
  16.     /* Finally, copy our source */
  17.     while(*ps){
  18.         *pd = *ps;
  19.         pd++;
  20.         ps++;
  21.     }
  22. }

Loudness Program: Gets loudness level from user; chooses a response And prints it using logical and operative statements

How to write a C Program to Gets loudness level from user; chooses a response And prints it using logical and operative statements in C Programming Language ?


Solution:


/* Gets loudness level from user; choses a response
 * And prints it using logical and operative statements.
 */

#include <stdio.h>

int main(){
	/* It's an int because it worked out weird with decimals */
	int Loudness, GoAgain;
	
	BEGINAGAIN:	
	
	printf("How loud (in decibel levels) are you? No decimals please.\n");
	scanf("%d", &Loudness);
	
	/* Determines the response: */
	if (Loudness <= 50)	/* reverts to this if more than 21 digits are entered */	
		printf("Speak up!!  You're too quiet\n\n");

	else if (Loudness > 50 && Loudness <= 70)	/*  51-70 */
		printf("That's better, now I can hear you\n\n");

	else if (Loudness > 70 && Loudness <= 90)	/*  71-90 */
		printf("Too loud, you are getting annoying\n\n");
	
	else if (Loudness > 90 && Loudness <= 110)	/* 91-110 */
		printf("Quiet, you ARE annoying!\n\n");

	else if (Loudness > 110)	/* Note - reverts to what I can only assumed to 
													be 0 when over 21 digits */
		printf("Ahhhh, now you sound like Mr. Adamakos!!!\n\n");
 
 	/* Should never be displayed */
    else 	
		printf("Error\n\n");

/* Debugging tool: Lets the code repeat over and over again.
 * Commented out because it causes weird reactions with decimals
 */
 /*
	printf("Go again? y = 1, n = 0\n");
	scanf("%d", &GoAgain);
	
	if(GoAgain == 1)
		{
		printf("\n\n");
		goto BEGINAGAIN;
		}
 */
		return 0;
}