Hello,
if the account number is "abcd" then i need to have to check whether "abcd1" or "abcd2" or ...... is existing or not.
if it is not existing then i need to create it.
so how can i do this
any suggestions
/****************************************************************
* File Name : c:\programs\tempCG.cpp
* Date : September,9,2009
* Comments : new project
* Compiler/Assembler : Visual C++ 6.0
* Modifications :
*
*
*
*
*
* Program Shell Generated At: 6:23:04 p.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#include < stdio.h >
#include < string.h >
#include < stdlib.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >
//main function ******************************
int main ( )
{
char str [ 20 ];
char numberStr [ 10 ];
strcpy ( str , "c:\\data\\file" );
int stringLength = strlen ( str );
int j = 0;
while ( j < 10 )
{
itoa ( j , numberStr, 10 );
strcpy ( str + stringLength , numberStr );
printf ( "%s" , str );
printf ( "\n" );
FILE * file = fopen ( str , "a" );
//..................
j ++;
}
return 0 ;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
char *reverse(char s[])
{
int c,i,j;
for(i=0,j=strlen(s)-1;i<j;i++,j--)
{
c=s[i];
s[i]=s[j];
s[j]=c;
}
return s;
}
char *itoa(int n)
{
char s[100];
int i,sign,ind=0,mod,w=0;
if((sign=n)<0){
if(sign<=INT_MIN)
{
mod=-(n%10);
n=n/10;
ind=1;
}
n=-n;
}
i=0;
do
{
if(ind==1)
{
s[0]=mod+'0';
i++;
ind=0;
}
s[i++]=n%10+'0';
}while((n/=10)>0);
s[i]='\0';
return (reverse(s));
}
int exists(const char *filename)
{
FILE *f = fopen(filename, "r");
if (!f) return 0;
fclose(f);
return 1;
}
int main ( )
{
char str [1024];
strcpy(str,"abcd");
int num = 0;
int created = 0;
while(created == 0)
{
num++;
if(exists(str))
{
char numb[100];
strcpy(str,"abcd");
strcpy(numb,"");
strcpy(numb,itoa(num));
strcat(str,numb);
}
else
{
FILE *f=fopen(str,"w");
printf("%s file created\n",str);
created=1;
fclose(f);
}
}
return 0 ;
}
Return to C/C++ Programming Language
Users browsing this forum: No registered users and 0 guests