Common Error Occurred While Using scanf Statement in C Language

Bhanu Priya
Updated on 09-Mar-2021 07:14:33

1K+ Views

ProblemCommon error occurred while reading string and numeric data using scanf() function in C languageSolutionThe scanf() function is used to read formatted input from stdin in C language. It returns the whole number of characters written in it otherwise, returns a negative value.Generally in case of scanf() function while reading string values after integer from the user, we get frequent errors.ExampleFollowing is a C program which reads roll number (integer value) and name of a student − Live Demo#include struct student {    char name[10];    int roll; } s; int main(){    printf("Enter information of students:");    printf("Enter roll ... Read More

Print a Name Multiple Times Without Loop Statement in C Language

Bhanu Priya
Updated on 09-Mar-2021 07:13:35

8K+ Views

ProblemTry to print a name 10 times without using any loop or goto statement in C programming language.SolutionGenerally, looping statements are used to repeat the block of code until condition is false.Example1In this program, we are trying to print a name 10 times without using loop or goto statements. Live Demo#include void printname(char* name,int count){    printf("%03d : %s",count+1,name);    count+=1;    if(count

Arguments in the Main Function in C Language

Bhanu Priya
Updated on 09-Mar-2021 07:10:36

5K+ Views

Yes, we can give arguments in the main() function.Command line arguments in C are specified after the name of the program in the system’s command line, and these argument values are passed on to your program during program execution.The argc and argv are the two arguments that can pass to main function.But main() function is actually called by the operating system (or shell program) when you run the program from the terminal.SyntaxThe syntax is explained below −int main(int argc, char *argv[]){    //Code    return 0; }Example Live Demo#include int main(int argc, char *argv[]){    int i;    for (i = ... Read More

Find ASCII Value of Uppercase Character A Using Implicit Conversion in C

Bhanu Priya
Updated on 09-Mar-2021 07:09:37

552 Views

Implicit type conversion is done by the compiler by converting smaller data type into a larger data type.For example, ASCII value of A=65.In this program, we are giving character ‘A’ as input, now write a code to convert A to 65 which is its ASCII value.ExampleFollowing is the example to find ASCII value of uppercase character ‘A’ using implicit conversion − Live Demo#include int main(){    char character = 'A';    int number = 0, value;    value = character + number; //implicit conversion    printf("The ASCII value of A is: %d", value);    return 0; }OutputThe ASCII value of ‘A’ ... Read More

Different Types of Functions in C Programming

Bhanu Priya
Updated on 09-Mar-2021 07:06:23

14K+ Views

Functions are broadly classified into two types which are as follows −predefined functionsuser defined functionsPredefined (or) library functionsThese functions are already defined in the system libraries.Programmer can reuse the existing code in the system libraries which is helpful to write error free code.User must be aware of syntax of the function.For instance, sqrt() function is available in math.h library and its usage is y= sqrt (x), where x= number must be positive.If x value is 25, i.e., y = sqrt (25) then ‘y’ = 5.In the same way, printf() is available in stdio.h library and clrscr() is available in conio.h ... Read More

4 Steps to Convert C Program to Machine Code

Bhanu Priya
Updated on 09-Mar-2021 07:03:14

5K+ Views

Process of Creating and Running ProgramsA program contains a set of instructions which was written in a programming language.The programmer’s job is to write and test the program.The 4 steps to convert a ‘C’ program into machine language are &miuns;Writing and editing the programCompiling the programLinking the programExecuting the programWriting and editing the program‘Text editors’ are used to write programs.With the help of text editors, users can enter, change and store character data.All special text editors are often included with a compiler.After writing the program, the file is saved to disk.It is known as ‘source file’.This file is input to ... Read More

Getting Information About MySQL Databases and Tables

AmitDiwan
Updated on 09-Mar-2021 06:58:50

247 Views

It is possible for the user to forget the name of the database or table or the structure of table or the name of the columns. This issue can be solved using MySQL since it supports many statements that provide information about the databases and tables which it supports.The ‘SHOW DATABASES’ query can be used to list all the databases that are managed by the server. To see which database is currently in use, the ‘DATABASE()’ function.Let us understand this query in the below section −Querymysql> SELECT DATABASE();Output+---------------------+ | DATABASE()          | +---------------------+ | databaseInUse     ... Read More

List Down All Tables in a MySQL Database

AmitDiwan
Updated on 09-Mar-2021 06:55:07

756 Views

Let us understand how to list down all the tables in a MySQL database −Once a database is created, we can access and use a specific database, using the following query −Querymysql> USE databaseName Database changedThe ‘USE’ statement doesn’t require a semi-colon. This is similar to the ‘QUIT’ statement. Even if semi-colon is used, it does no harm. We can create and use a database of our own, but before that, MySQL administrator’s permission is required.The MySQL administrator can execute a command as shown below to provide permissions −mysql> GRANT ALL ON tableName.* TO ‘your_mysql_name’@’your_client_host’;Here, ‘your_mysql_name’ refers to the MySQL ... Read More

Connect to MySQL Database from Command Line

AmitDiwan
Updated on 09-Mar-2021 06:54:22

4K+ Views

Let us understand how MySQL can be connected to the database using the command-line. This is done for clients like mysql or mysqldump.The below command invokes mysql without specifying any explicit connection parameters −mysqlSince there are no parameter options, the default values will be applied −The default host name is localhost.The default user name is ODBC on Windows.No password is sent because neither --password nor -p has been mentioned.For mysql, the first non-option argument is considered the name of the default database. Since there is no such argument, mysql selects no default database.To specify the host name, user name and ... Read More

Get Minimum and Maximum Value in MySQL

AmitDiwan
Updated on 09-Mar-2021 06:51:46

2K+ Views

We need to use the MAX(columnName) to find the Maximum value in a column, whereas use the MIN(columnName) to find the Maximum value in a column.Let’s say following is the syntax to find the highest and lowest value in a specific column −mysql> SELECT @min_val:=MIN(columnName), @max_val:=MAX(columnName) FROM tableName; mysql> SELECT * FROM tableName WHERE columnName=@min_val OR columnName=@max_val;Note: Let’s say we have a database named ‘StudentsRecords’ and a table named ‘STUDENT.Following is our table −StudentIdStudentMarksS00190S00297S00372We will now write the query −Querymysql> SELECT @min_val:=MIN(StudentMarks), @max_val:=MAX(StudentMarks) FROM STUDENT; mysql> SELECT * FROM STUDENT WHERE StudentMarks =@min_val OR StudentMarks =@max_val;Output+---------------------+ | StudentMarks   ... Read More

Advertisements