#include <stdio.h>
#include <string.h>
#define SIZE 30
int main()
{
char name[ SIZE ];
FILE *fpPtr;
if ( ( fpPtr = fopen( "sorted_file.txt", "r" ) ) == NULL ) {
printf( "File could not be opened\n" );
}
else {
printf( "%s\n", "Name" );
fscanf( fpPtr, "%s", name );
while( !feof( fpPtr ) ) {
printf( "%s\n", name );
fscanf( fpPtr, "%s", name );
}
fclose( fpPtr );
}
return 0;
};
Hay friends .. AREA OF LANGUAGE IS TOO WIDE BUT NOW APPROXIMATE THEORY AND "C PROGRAMING CODES" ARE AVAILABLE . GOPAL KRISHNA "CHAUHAN"
Monday, 17 June 2013
;)
Sunday, 3 March 2013
How to print the memory usage : C Programming by "Gopal Krishna"
You want to find out how much memory is this program using .
Any code or function
i should add to find the total memory used by this program.
I don't want to check task manager for this.
I need to print the memory usage.
#include <stdio.h>
#include <string.h>
#define SIZE 30
int main()
{
char name[ SIZE ];
FILE *fpPtr;
if ( ( fpPtr = fopen( "sorted_file.txt", "r" ) ) == NULL ) {
printf( "File could not be opened\n" );
}
else {
printf( "%s\n", "Name" );
fscanf( fpPtr, "%s", name );
while( !feof( fpPtr ) ) {
printf( "%s\n", name );
fscanf( fpPtr, "%s", name );
}
fclose( fpPtr );
}
return 0;
};
Try This ..........................
C Programming By GOPAL KRISHNA
Saturday, 23 February 2013
Creation of viruses V I A C Programming .
THIS TUT. ONLY FOR STUDY PURPOSE
I SAY BEFORE , A STYLE OF TRICK ,
HOW TO SHUT DOWN THE SYSTEM IN LAST PROGRAM ....
NOW :
C program such that when we will click on its .exe file then it will open internet explorer at infinite times?
Step 1 : write code :
#include<stdio.h>
#include<dos.h>
int main (void){
for(; ;){
system("c:\\progra~1\\intern~1\\iexplore.exe");
}
return 0;
}
Step 2: Save the above file. Let file name is internet.c
Step 3: Only compile the above program.
Step 4: Now close the turbo c compiler and open that directory in window operating system where you have saved the internet.c (default directory c:\tc\bin)
Step 5: Double click on its .exe file (internet.exe)
This is the creation of simple virus ... which is simpal and kool WAIT FOR MORE ......
(C by Gopal Krishna)
NOW :
C program such that when we will click on its .exe file then it will open internet explorer at infinite times?
Step 1 : write code :
#include<stdio.h>
#include<dos.h>
int main (void){
for(; ;){
system("c:\\progra~1\\intern~1\\iexplore.exe");
}
return 0;
}
Step 2: Save the above file. Let file name is internet.c
Step 3: Only compile the above program.
Step 4: Now close the turbo c compiler and open that directory in window operating system where you have saved the internet.c (default directory c:\tc\bin)
Step 5: Double click on its .exe file (internet.exe)
This is the creation of simple virus ... which is simpal and kool WAIT FOR MORE ......
(C by Gopal Krishna)
Friday, 21 September 2012
C programming code for Ubuntu Linux
#include <stdio.h>
int main() {
system("shutdown -P now");
return 0;
}
C programming code for Windows 7
#include <stdio.h>
#include <stdlib.h>
main()
{
char ch;
printf("Do you want to shutdown your computer now (y/n)\n");
scanf("%c",&ch);
if (ch == 'y' || ch == 'Y')
system("C:\\WINDOWS\\System32\\shutdown /s");
return 0;
}
C program to shutdown or turn off computer
If you are using Turbo C Compiler then execute
your file from folder. Press F9 to build your executable file from
source program. When you run from within the compiler by pressing
Ctrl+F9 it may not work.
C programming code for Windows XP
#include <stdio.h>
#include <stdlib.h>
main()
{
char ch;
printf("Do you want to shutdown your computer now (y/n)\n");
scanf("%c",&ch);
if (ch == 'y' || ch == 'Y')
system("C:\\WINDOWS\\System32\\shutdown -s");
return 0;
}
c program to get ip address
C programming code
#include<stdlib.h>
main()
{
system("C:\\Windows\\System32\\ipconfig");
system("pause");
return 0;
}
c program to print date
C programming code
#include<stdio.h>
#include<conio.h>
#include<dos.h>
main()
{
struct date d;
getdate(&d);
printf("Current system date is %d/%d/%d",d.da_day,d.da_mon,d.da_year);
getch();
return 0;
}
c program to add two complex numbers
C programming code
#include <stdio.h>
struct complex
{
int real, img;
};
main()
{
struct complex a, b, c;
printf("Enter a and b where a + ib is the first complex number.\n");
printf("a = ");
scanf("%d", &a.real);
printf("b = ");
scanf("%d", &a.img);
printf("Enter c and d where c + id is the second complex number.\n");
printf("c = ");
scanf("%d", &b.real);
printf("d = ");
scanf("%d", &b.img);
c.real = a.real + b.real;
c.img = a.img + b.img;
if ( c.img >= 0 )
printf("Sum of two complex numbers = %d + %di\n",c.real,c.img);
else
printf("Sum of two complex numbers = %d %di\n",c.real,c.img);
return 0;
}
C programming code using random function(Turbo C compiler only)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int n, max, num, c;
printf("Enter the number of random numbers you want ");
scanf("%d",&n);
printf("Enter the maximum value of random number ");
scanf("%d",&max);
printf("%d random numbers from 0 to %d are :-\n",n,max);
randomize();
for ( c = 1 ; c <= n ; c++ )
{
num = random(max);
printf("%d\n",num);
}
getch();
return 0;
}
c program to generate random numbers
C programming code using rand
#include <stdio.h>
#include <stdlib.h>
int main() {
int c, n;
printf("Ten random numbers in [1,100]\n");
for (c = 1; c <= 10; c++) {
n = rand()%100 + 1;
printf("%d\n", n);
}
return 0;
}
c program to delete a file
C programming code
#include<stdio.h>
main()
{
int status;
char file_name[25];
printf("Enter the name of file you wish to delete\n");
gets(file_name);
status = remove(file_name);
if( status == 0 )
printf("%s file deleted successfully.\n",file_name);
else
{
printf("Unable to delete the file\n");
perror("Error");
}
return 0;
}
c program to list files in directory
C programming code
#include<stdio.h>
#include<conio.h>
#include<dir.h>
main()
{
int done;
struct ffblk a;
printf("Press any key to view the files in the current directory\n");
getch();
done = findfirst("*.*",&a,0);
while(!done)
{
printf("%s\n",a.ff_name);
done = findnext(&a);
}
getch();
return 0;
}
c program to merge two files
C programming code
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
FILE *fs1, *fs2, *ft;
char ch, file1[20], file2[20], file3[20];
printf("Enter name of first file ");
gets(file1);
printf("Enter name of second file ");
gets(file2);
printf("Enter name of file which will store contents of two files ");
gets(file3);
fs1 = fopen(file1,"r");
fs2 = fopen(file2,"r");
if( fs1 == NULL || fs2 == NULL )
{
perror("Error ");
printf("Press any key to exit...\n");
getch();
exit(EXIT_FAILURE);
}
ft = fopen(file3,"w");
if( ft == NULL )
{
perror("Error ");
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while( ( ch = fgetc(fs1) ) != EOF )
fputc(ch,ft);
while( ( ch = fgetc(fs2) ) != EOF )
fputc(ch,ft);
printf("Two files were merged into %s file successfully.\n",file3);
fclose(fs1);
fclose(fs2);
fclose(ft);
getch();
return 0;
}
program to copy files
C
program to copy files: This program copies a file, firstly you will
specify the file to copy and then you will enter the name of target
file, You will have to mention the extension of file also. We will open
the file that we wish to copy in read mode and target file in write
mode.
C programming code
#include <stdio.h>
#include <stdlib.h>
main()
{
char ch, source_file[20], target_file[20];
FILE *source, *target;
printf("Enter name of file to copy\n");
gets(source_file);
source = fopen(source_file, "r");
if( source == NULL )
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
printf("Enter name of target file\n");
gets(target_file);
target = fopen(target_file, "w");
if( target == NULL )
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while( ( ch = fgetc(source) ) != EOF )
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
c program to read a file
C program to open a file
C programming code to open a file and to print it contents on screen.#include<stdio.h>
#include<stdlib.h>
main()
{
char ch, file_name[25];
FILE *fp;
printf("Enter the name of file you wish to see ");
gets(file_name);
fp = fopen(file_name,"r"); // read mode
if( fp == NULL )
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are :- \n\n", file_name);
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
fclose(fp);
return 0;
}
String concatenation without strcat
#include<stdio.h>
void concatenate_string(char*, char*);
main()
{
char original[100], add[100];
printf("Enter source string\n");
gets(original);
printf("Enter string to concatenate\n");
gets(add);
concatenate_string(original, add);
printf("String after concatenation is \"%s\"\n", original);
return 0;
}
void concatenate_string(char *original, char *add)
{
while(*original)
original++;
while(*add)
{
*original = *add;
add++;
original++;
}
*original = '\0';
}
c program to concatenate strings
C code
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
strcat(a,b);
printf("String obtained on concatenation is %s\n",a);
getch();
return 0;
}
Change string to lower case without strlwr
#include<stdio.h>
void lower_string(char*);
main()
{
char string[100];
printf("Enter a string to convert it into lower case\n");
gets(string);
lower_string(string);
printf("Entered string in lower case is \"%s\"\n", string);
return 0;
}
void lower_string(char *string)
{
while(*string)
{
if ( *string >= 'A' && *string <= 'Z' )
{
*string = *string + 32;
}
string++;
}
}
Change string to upper case without strupr
#include<stdio.h>
void upper_string(char*);
main()
{
char string[100];
printf("Enter a string to convert it into upper case\n");
gets(string);
upper_string(string);
printf("Entered string in upper case is \"%s\"\n", string);
return 0;
}
void upper_string(char *string)
{
while(*string)
{
if ( *string >= 'a' && *string <= 'z' )
{
*string = *string - 32;
}
string++;
}
}
Subscribe to:
Posts (Atom)