C program for command line argument

Write c program to accepts file name at command line argument and coverts all characters in the file to uppercase ?

Questions by souji1425

Showing Answers 1 - 3 of 3 Answers

bmlal

  • Jul 14th, 2006
 

int main(int argc, char *argv[])
{
FILE *fp; char ch;

if (argc != 2)
{

printf("pass two argumentsn");
exit (-1);
}
fp = fopen(argv[1], "r+");
if (fp == NULL)
{
printf("error in file openingn");
exit (-1);
} ch = fgetc(fp);
while (ch != EOF)
{
if (ch greaterThan=97 && ch lessTan<=122)
{

fseek(fp, -1, SEEK_CUR);
fputc(ch-32, fp);
}
putchar(ch);
ch = fgetc(fp);
}
}

NOTE: Replace greaterThan, lessThan with corresponding logical operator as this text box is not allowing to enter those operators directly.

  Was this answer useful?  Yes

bmlal

  • Jul 14th, 2006
 

int main(int argc, char *argv[]){ FILE *fp; char ch; if (argc != 2) { printf("pass two argumentsn"); exit (-1); } fp = fopen(argv[1], "r+"); if (fp == NULL) { printf("error in file openingn"); exit (-1); } ch = fgetc(fp); while (ch != EOF) { if (ch greaterThan=97 && ch lessTan<=122) { fseek(fp, -1, SEEK_CUR); fputc(ch-32, fp); } putchar(ch); ch = fgetc(fp); }}NOTE: Replace greaterThan, lessThan with corresponding logical operator as this text box is not allowing to enter those operators directly.

  Was this answer useful?  Yes

#include "stdafx.h"

#include <iostream>
int main(int argc, char*argv[])

{

FILE* fp = NULL;

char * fileName = "File.cpp";

fp = fopen(fileName,"r");

char c = getc(fp);while (c != EOF)

{

c = toupper(c);

putchar(c);

c = getc(fp);

}


fclose (fp);

return 0;

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions