/*
* CreatePath.c
*
* Created on: Feb 28, 2011
* Author: Karthikeyan.D
*/
#include <stdlib.h>
#include <stdio.h>
int main()
{
char path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_makepath(path_buffer, "D", "\\Testdir\\myexample\\", "testfile", "txt");
printf("Path created with _makepath(): %s\n", path_buffer);
_splitpath(path_buffer, drive, dir, fname, ext);
printf("Path extracted with _splitpath():\n");
printf(" Drive: %s\n", drive);
printf(" Dir: %s\n", dir);
printf(" Filename: %s\n", fname);
printf(" Ext: %s\n", ext);
return 0;
}
OUTPUT:
Path created with _makepath(): D:\Testdir\myexample\testfile.txt
Path extracted with _splitpath():
Drive: D:
Dir: \Testdir\myexample\
Filename: testfile
Ext: .txt
Sunday, February 27, 2011
Displaying the current working directories path through C coding
/*
* DisplayPath.c
*
* Created on: Feb 28, 2011
* Author: karthikeyan.D
*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>
void DisplayFullPath(char *relPath)
{
/*Buffer*/
char full[_MAX_PATH];
if(_fullpath(full, relPath, _MAX_PATH) != NULL)
printf("The full path is: %s\n", full);
else
printf("Invalid path\n");
}
int main()
{
// For displaying the actual path
DisplayFullPath("test.txt");
// For displaying the current working directory and file name
DisplayFullPath("\\test.txt");
// Displaying up to two sub_directories
DisplayFullPath("..\\test.txt");
// Display full path
DisplayFullPath(".");
return 0;
}
OUTPUT:
The full path is: E:\WORK\March2011\DispalyFullPath\test.txt
The full path is: E:\test.txt
The full path is: E:\WORK\March2011\test.txt
The full path is: E:\WORK\March2011\DispalyFullPath
* DisplayPath.c
*
* Created on: Feb 28, 2011
* Author: karthikeyan.D
*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>
void DisplayFullPath(char *relPath)
{
/*Buffer*/
char full[_MAX_PATH];
if(_fullpath(full, relPath, _MAX_PATH) != NULL)
printf("The full path is: %s\n", full);
else
printf("Invalid path\n");
}
int main()
{
// For displaying the actual path
DisplayFullPath("test.txt");
// For displaying the current working directory and file name
DisplayFullPath("\\test.txt");
// Displaying up to two sub_directories
DisplayFullPath("..\\test.txt");
// Display full path
DisplayFullPath(".");
return 0;
}
OUTPUT:
The full path is: E:\WORK\March2011\DispalyFullPath\test.txt
The full path is: E:\test.txt
The full path is: E:\WORK\March2011\test.txt
The full path is: E:\WORK\March2011\DispalyFullPath
Random order for array elements
/*
* RandomOrder.c
*
* Created on: Feb 28, 2011
* Author: Karthikeyan.D
*/
# include <stdio.h>
# include <windows.h>
int main()
{
//Variable Declaration
int szArray[20];
int i,SwapIndex,temp;
// Value Assignment
for(i=0;i<20;i++)
szArray[i]=i+1;
//Array Value Shuffling
for(i=0; i<20;i++)
{
do
{
SwapIndex = rand()+1;
}while(SwapIndex >= 20);
temp = szArray[i];
szArray[i] = szArray[SwapIndex];
szArray[SwapIndex] = temp;
}
// Dispaly part
for(i=0;i<20;i++)
printf("%d\n",szArray[i]);
return 0;
}
OUTPUT:
10
1
7
11
6
17
5
16
8
20
18
12
13
9
3
2
19
4
15
14
* RandomOrder.c
*
* Created on: Feb 28, 2011
* Author: Karthikeyan.D
*/
# include <stdio.h>
# include <windows.h>
int main()
{
//Variable Declaration
int szArray[20];
int i,SwapIndex,temp;
// Value Assignment
for(i=0;i<20;i++)
szArray[i]=i+1;
//Array Value Shuffling
for(i=0; i<20;i++)
{
do
{
SwapIndex = rand()+1;
}while(SwapIndex >= 20);
temp = szArray[i];
szArray[i] = szArray[SwapIndex];
szArray[SwapIndex] = temp;
}
// Dispaly part
for(i=0;i<20;i++)
printf("%d\n",szArray[i]);
return 0;
}
OUTPUT:
10
1
7
11
6
17
5
16
8
20
18
12
13
9
3
2
19
4
15
14
Saturday, February 26, 2011
Thursday, February 10, 2011
Verbose Option
include <stdio.h>
# include <stdlib.h>
int main()
{
//Using this line we can assign 0 for all the array element.
int a[10]={};
//This line declare the array with some garbage value.
int b[10];
//This line used to set the first element value as one and remaining all are zero's.
int c[10]={1};
int i=0;
//This for loop used for printing the array element and their index value's.
for(;i<10;i++)
{
printf("Index%d-content=%d\tIndex%d-content=%d\tIndex%d-content=%d\n",i,a[i],i,c[i],i,b[i]);
}
return 0;
}
Output:
Index0-content=0 Index0-content=1 Index0-content=-2
Index1-content=0 Index1-content=0 Index1-content=1982242980
Index2-content=0 Index2-content=0 Index2-content=1982310602
Index3-content=0 Index3-content=0 Index3-content=3411632
Index4-content=0 Index4-content=0 Index4-content=3411568
Index5-content=0 Index5-content=0 Index5-content=2293552
Index6-content=0 Index6-content=0 Index6-content=1982310408
Index7-content=0 Index7-content=0 Index7-content=0
Index8-content=0 Index8-content=0 Index8-content=0
Index9-content=0 Index9-content=0 Index9-content=2147315712
# include <stdlib.h>
int main()
{
//Using this line we can assign 0 for all the array element.
int a[10]={};
//This line declare the array with some garbage value.
int b[10];
//This line used to set the first element value as one and remaining all are zero's.
int c[10]={1};
int i=0;
//This for loop used for printing the array element and their index value's.
for(;i<10;i++)
{
printf("Index%d-content=%d\tIndex%d-content=%d\tIndex%d-content=%d\n",i,a[i],i,c[i],i,b[i]);
}
return 0;
}
Output:
Index0-content=0 Index0-content=1 Index0-content=-2
Index1-content=0 Index1-content=0 Index1-content=1982242980
Index2-content=0 Index2-content=0 Index2-content=1982310602
Index3-content=0 Index3-content=0 Index3-content=3411632
Index4-content=0 Index4-content=0 Index4-content=3411568
Index5-content=0 Index5-content=0 Index5-content=2293552
Index6-content=0 Index6-content=0 Index6-content=1982310408
Index7-content=0 Index7-content=0 Index7-content=0
Index8-content=0 Index8-content=0 Index8-content=0
Index9-content=0 Index9-content=0 Index9-content=2147315712
Tuesday, February 1, 2011
Deleting the number of lines without using other files
/*
* DeleteTrace.c
*
* Created on: Feb 1, 2011
* Author: Karthikeyan.D
*/
# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <stdlib.h>
int main()
{
// Variable Declaration
FILE *FRead,*FWrite;
char SzContent[1000];
long int nloop;
long int nLineIndex;
/* File read and Read/write Mode Operation*/
// Here You Can Your File Location.
printf("Enter file File Path \n");
gets(SzContent);
FRead = fopen(SzContent,"r");
FWrite = fopen(SzContent,"r+");
if(FRead == NULL)
{
MessageBox(NULL,"Please Specify Already Created File Location ","Error in File Location",16);
exit(0);
}
printf("Enter the Line Index \n");
scanf("%ld",&nLineIndex);
/* This function is used to remove the number lines*/
for (nloop=0;nloop<nLineIndex;nloop++)
{
fgets(SzContent,1000,FRead);
}
/* This function is used to overwrite content from the top of the line*/
while(fgets(SzContent,1000,FRead)!=NULL)
{
fprintf(FWrite,SzContent);
}
/* To close the Two File Pointer */
fclose(FRead);
fclose(FWrite);
getch();
return 0;
}
Monday, January 31, 2011
C++ Constructor Concept
/*
* Devices.cpp
*
* Created on: Jan 27, 2011
* Author: Karthikeyan.D
*/
#include "Devices.h"
Devices::Devices() {
// TODO Auto-generated constructor stub
cout<<"Hello World1"<<endl;
}
Devices::~Devices() {
// TODO Auto-generated destructor stub
cout<<"Hello World2"<<endl;
}
int main()
{
Devices Obj;
Obj.chair();
return 0;
}
---------------------------------------------------------------------------------------------------------
/*
* Devices.h
*
* Created on: Jan 27, 2011
* Author: Karthikeyan.D
*/
#ifndef DEVICES_H_
#define DEVICES_H_
# include
class Devices {
public:
//int Chair();
int chair()
{
cout << "This method is used to understand the Object creation in the C++ "<<endl;
return 0;
}
Devices();
virtual ~Devices();
};
#endif /* DEVICES_H_ */
________________________________________________________________________________
OUTPUT:
Hello World1
This method is used to understand the Object creation in the C++
Hello World2
* Devices.cpp
*
* Created on: Jan 27, 2011
* Author: Karthikeyan.D
*/
#include "Devices.h"
Devices::Devices() {
// TODO Auto-generated constructor stub
cout<<"Hello World1"<<endl;
}
Devices::~Devices() {
// TODO Auto-generated destructor stub
cout<<"Hello World2"<<endl;
}
int main()
{
Devices Obj;
Obj.chair();
return 0;
}
---------------------------------------------------------------------------------------------------------
/*
* Devices.h
*
* Created on: Jan 27, 2011
* Author: Karthikeyan.D
*/
#ifndef DEVICES_H_
#define DEVICES_H_
# include
class Devices {
public:
//int Chair();
int chair()
{
cout << "This method is used to understand the Object creation in the C++ "<<endl;
return 0;
}
Devices();
virtual ~Devices();
};
#endif /* DEVICES_H_ */
________________________________________________________________________________
OUTPUT:
Hello World1
This method is used to understand the Object creation in the C++
Hello World2
Saturday, November 13, 2010
How to display the message box through Command Prompt
How to display the message box through Command Prompt
Procedure:
Step 1: Go to “Start” Menu and Click Run option.
Step 2: Enter “cmd” in drop down box.
Step 3: In CMD window, Type as “msg Console [User Content]”.
Ex: msg console Enjoy life with new technology!!!
OUTPUT:
Monday, November 1, 2010
How to find the variable size without using Sizeof function
/*
* sizeofVariable.c
* Author : karthikeyan.D
* Date: 1-Nov-2010
*
*/
/* please refer this following statements.
#ifndef __SIZE_T
#define __SIZE_T
typedef unsigned int size_t;
#endif
.... meaning that on this particular implementation `size_t' is
an `unsigned int'.
*/
# include <stdio.h>
# include <stdlib.h>
//user definition
# define size_var( var ) ((size_t)(&(var)+1)-(size_t)(&(var)))
int main()
{
int nVal;
char cChar;
printf("size of :%d\n",size_var(nVal));
printf("size of :%d",size_var(cChar));
return 0;
}
* sizeofVariable.c
* Author : karthikeyan.D
* Date: 1-Nov-2010
*
*/
/* please refer this following statements.
#ifndef __SIZE_T
#define __SIZE_T
typedef unsigned int size_t;
#endif
.... meaning that on this particular implementation `size_t' is
an `unsigned int'.
*/
# include <stdio.h>
# include <stdlib.h>
//user definition
# define size_var( var ) ((size_t)(&(var)+1)-(size_t)(&(var)))
int main()
{
int nVal;
char cChar;
printf("size of :%d\n",size_var(nVal));
printf("size of :%d",size_var(cChar));
return 0;
}
Subscribe to:
Posts (Atom)