/*WAP to copy content of one file to another
i) As it is.
ii) After converting all characters to upper case
Name: Shivam*/
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<stdlib.h>
void main()
{
clrscr();
char path1[100], path2[100], ch, ch2;
int cho;
cout<<"\n\tEnter the path of the file which has to be copied: ";
gets (path1);
ifstream org(path1);
if(!org)
{
cout<<"\tFile not found!";
exit(0);
}
cout<<"Enter the name or the path of the file where the file has to be copied to: ";
gets(path2);
ofstream wrt(path2);
if(!wrt)
{
cout<<"\tCannot create file!";
exit(0);
}
cout<<"\t 1. Enter 1 to copy file as it is. \n\t 2. Enter 2 to copy file after converting all lower case characters to upper case characters. \n\n\t Enter your choice: ";
cin>>cho;
if(cho==1)
{
do{
org.get(ch);
wrt.put(ch);
}while(!org.eof());
}
else
{
if(cho==2)
{
do{
org.get(ch);
if(ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'e' || ch == 'f' || ch == 'g' || ch == 'h' || ch == 'i' || ch == 'j' || ch == 'k' || ch == 'l' || ch == 'm' || ch == 'n' || ch == 'o' || ch == 'p' || ch == 'q' || ch == 'r' || ch == 's' || ch == 't' || ch == 'u' || ch == 'v' || ch == 'w' || ch == 'x' || ch == 'y' || ch == 'z')
{
ch2 = ch - 32;
wrt.put(ch2);
}
else
wrt.put(ch);
}while(!org.eof());
}
else
cout<<"Wrong choice entered!";
}
}
VanishingNerd said:Umm why this??
if(ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'e' || ch == 'f' || ch == 'g' || ch == 'h' || ch == 'i' || ch == 'j' || ch == 'k' || ch == 'l' || ch == 'm' || ch == 'n' || ch == 'o' || ch == 'p' || ch == 'q' || ch == 'r' || ch == 's' || ch == 't' || ch == 'u' || ch == 'v' || ch == 'w' || ch == 'x' || ch == 'y' || ch == 'z')
why not ch > 96 && ch <123 ??
main(argc, argv)
int argc;
char **argv;
{
while (*argv != argv[1] && (*argv = argv[1]) && (argc = 0) || (*++argv
&& (**argv && ((++argc)[*argv] && (**argv <= argc[*argv] ||
(**argv += argc[*argv] -= **argv = argc[*argv] - **argv)) &&
--argv || putchar(**argv) && ++*argv--) || putchar(10))))
;
}
Umm why this??VanishingNerd said:Umm why this??
why not ch > 96 && ch <123 ??
:ashamed: DAnM !!!! y didn't it get into my mind, it took me a long time 2 write this.!!! thanx!!!!VanishingNerd said:Umm why this??
if(ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'e' || ch == 'f' || ch == 'g' || ch == 'h' || ch == 'i' || ch == 'j' || ch == 'k' || ch == 'l' || ch == 'm' || ch == 'n' || ch == 'o' || ch == 'p' || ch == 'q' || ch == 'r' || ch == 's' || ch == 't' || ch == 'u' || ch == 'v' || ch == 'w' || ch == 'x' || ch == 'y' || ch == 'z')
why not ch > 96 && ch <123 ??
+1H@cKer said:as he is also learning every one has its own way of writing a program.
there r similar threads in other forum also. we can all post already made prgs & ask for help in improving existing 1's but doing other ppls assignment won't be done!!!booo said:@mahvis: bad bad idea... I agree with keane on this. I have seen many people posting in forums to get their assignment answers. I dont think I would help such people.
btw, can you write the same program that you wrote above without using the if condition? :bleh:
i'm confused about this part. will it work????Yamaraj said:Umm why this??
Why not (ch >= 'a' && ch <= 'z')??
You're familiar with the hazards of using magic numbers and non-portable character sets, aren't you? (Hint: ASCII and EBCDIC)
no projects will be entertained here!!!! if u complete this prg on ur own then u can post it here or if u want a bit help u can ask for help!!!cool1 said:any 1 knows program floyd's triangle using c#
for this
1
every1 has here own views!!! u feel its not right, i feel its right.hammerhead said:Bad bad idea. Keane's right.
wat does this do????viridian said:From
Hello World ! - GNU Project - Free Software Foundation (FSF)
#include <iostream.h>
#include <string.h>
class string
{
private:
int size;
char *ptr;
public:
string() : size(0), ptr(new char('\0')) {}
string(const string &s) : size(s.size)
{
ptr = new char[size + 1];
strcpy(ptr, s.ptr);
}
~string()
{
delete [] ptr;
}
friend ostream &operator <<(ostream &, const string &);
string &operator=(const char *);
};
ostream &operator<<(ostream &stream, const string &s)
{
return(stream << s.ptr);
}
string &string:perator=(const char *chrs)
{
if (this != &chrs)
{
delete [] ptr;
size = strlen(chrs);
ptr = new char[size + 1];
strcpy(ptr, chrs);
}
return(*this);
}
int main()
{
string str;
str = "Hello World";
cout << str << endl;
return(0);
}
mavihs said:wat does this do????
pr0ing said:its the Hello World Program.
prints 'Hello World' as output.
cout<<"Hello World"
# include <stdio.h>
# include <conio.h>
# include <string.h>
main()
{
char arg[20],new[20];
int i,j,k;
clrscr();
printf("Enter the string: ");
gets(arg);
printf("The value that you have entered is ---> %s",arg);
i = strlen(arg);
printf("\nThe length of the string is ---> %d", i);
for(j=0;j<=i;j++)
{
for(k=j;k<=i;k++) new[k-j] = arg[k];
for(k=0;k<j;k++) new[i-j+k] = arg[k];
printf("\n%s",new);
}
getch();
}
Enter the string: Ranjini
The value that you have entered is ---> Ranjini
The length of the string is ---> 7
Ranjini
anjiniR
njiniRa
jiniRan
iniRanj
niRanji
iRanjin
Ranjini