SlideShare a Scribd company logo
1 of 10
Download to read offline
So I am writing a CS code for a project and I keep getting "cannot open file" I know I put it into
my code, but I don't know why it won't execute after i input ./a.out I put in gcc -Wall
contents3.c and no errors or warnings pop up. So I figure everything is working right. But after
that, I get "Cannot open file". So I am wondering what I can do to get this settled out properly. I
am putting the outcome of the project and my code. Please someone help me!
#include
#include
#include
#include
#include
#include
int len = 0;
int sp = 0;
int lwrcaseCount = 0;
int uprcaseCount = 0;
int digitCount = 0;
int specialCount = 0;
char data[200];
int frequency[84];
int sortFrequency[84][2];
char string[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-
./:;<=>?@[/]^_`{|}~";
//printf(" ");
//To sort based on frequency of characters
/*void sort()
{
int max, loc, temp, x, y;
//Loops till end - 1 position of the frequency array
for(x = 0; x <= 84 - 1; x++)
{
//Initializes the max to the x position of the frequency array assuming it as maximum
max = frequency[x];
//Initializes of loc to x assuming location x contains the maximum value
loc = x;
//Loops through x + 1 to length - 1 of frequency array
for(y = x + 1; y <= 95 -1; y++)
{
//If current position of the frequency of the array is greater than the max
//then update the max with the current value of frequency and update the loc
if(frequency[y] > max)
{
max = frequency[y];
loc = y;
}//end of if
}//end of for loop
//If loc is not x then swap
if(loc != x)
{
temp = frequency[x];
frequency[x] = frequency[loc];
frequency[loc] = temp;
}//end of if
//Store the location of the maximum value in the zero column position of row x
sortFrequency[x][0]= loc;
//Store the maximum value in the first column position of row x
sortFrequency[x][1] = max;
}//end of for loop
}//end of function*/
void sort()
{
for(int i = 0; i < 84; i++)
{
sortFrequency[i][0] = i;
sortFrequency[i][1] = frequency[i];
}
for(int i = 0; i < 84-1; i++)
for(int j = 0; j < 84-i-1; j++)
if(sortFrequency[j][1] < sortFrequency[j+1][1])
{
int temp = sortFrequency[j][1];
sortFrequency[j][1] = sortFrequency[j+1][1];
sortFrequency[j+1][1] = temp;
temp = sortFrequency[j][0];
sortFrequency[j][0] = sortFrequency[j+1][0];
sortFrequency[j+1][0] = temp;
}
}
//To count frequency of each character
void frequencyCount()
{
int c, d;
//Loops till the length of the inputed data
for(c = 0; c < len; c++)
{
//Loops from 33 to 126 which is the ascii values of required characters range
for(d = 0; d < 84; d++)
{
//If the data in the current position is equal to the acii value
if(data[c] == string[d])
//Frequency 0 position is equal to 33 ascii.
//So 33 is deducted
frequency[d]++;
}//end of for loop
}//end of for loop
}//End of function
//Initializes the frequency array to zero
void initialize()
{
int c;
for(c = 0; c < 84; c++)
frequency[c] = 0;
}
//Read the file which contains data
void readFile()
{
//File pointer created
FILE *fptr;
char ch;
//File opened in read mode
fptr = fopen("Data1.txt", "r");
//If fptr is null show error message and terminate
if (fptr == NULL)
{
printf("Cannot open file  ");
exit(0);
}//end of if
//read the first character from the file
ch = fgetc(fptr);
//Loops till end of file
while (ch != EOF)
{
//Stores the character in data array
data[len++] = ch;
//reads another character from the file
ch = fgetc(fptr);
}//end of while
//close file
fclose(fptr);
}//End of method
//Display the required information
void dispData()
{
int c;
//Displays the file contents
printf(" Entered Data  ");
for(c = 0; c < len; c++)
printf("%c", data[c]);
printf(" %d characters", len - sp);
printf(" lowercase = %d and ", lwrcaseCount);
printf("uppercase = %d and ", uprcaseCount);
printf("digit = %d", digitCount);
printf(" and special = %d  ", specialCount);
for(c = 0; c < 84; c++)
{
if(c == 0 || sortFrequency[c][1] != sortFrequency[c-1][1])
printf(" Characters occurring %d times : ", sortFrequency[c][1]);
printf("%c ", string[sortFrequency[c][0]]);
}
/*for(c = 0; c < 95; c++)
{
if(sortFrequency[c][1] != 0)
printf(" Character %c occurs %d Times ", sortFrequency[c][0]+33, sortFrequency[c][1]);
}//end of for
printf(" Characters not found in input: ");
for(c = 0; c < 95; c++)
{
if(sortFrequency[c][1] == 0)
//printf(" Character %c occurs %d Times ", sortFrequency[c][0]+33, sortFrequency[c][1]);
printf("%c ", sortFrequency[c][0]);
}//end of for*/
printf(" ");
}//end of function
//Counts lowercase, uppercase, digits, special characters and total characters
void count()
{
int c;
for(c = 0; c < len; c++)
{
if(islower(data[c]))
lwrcaseCount++;
else if (isupper(data[c]))
uprcaseCount++;
else if (isdigit(data[c]))
digitCount++;
else if (ispunct(data[c]))
specialCount++;
else
sp++;
}//end of for
}//end of function
//Main function
int main()
{
//Calls the methods
initialize();
readFile();
count();
frequencyCount();
//dispData();
sort();
dispData();
return 0;
} Project overview: Ever wonder what is in a file? Ever wonder how many times each character
actually occurs in the file? Probably not most people never think of things like that. This
program takes an input source and tells the user what characters that source contains. It does not
worry about whitespace (spaces, tabs, newlines) but instead focuses on the printable characters.
These include: 26 upper-case letters, A-Z and 26 lower-case letters, a and 10 digits, 0-9 32
special characters: "#$S&' C [V1 This program reads from standard input until end-of-file.
Once it hits end-of-file, it tells the user what characters it saw, ordered from the most-occurring
character down to the characters that it did not see. As an example, if the user entered the input
below (shown in re the program generates the output shown in blue The Quick Brown Fox
Jumps over the Lazy Old Dog 123456789012345 the quick brown fox jumps over the lazy old
dog 105 characters lower case 67 and uppercase 9 and digit-15 and special 14 Characters
occurring 8 times o Characters occurring 6 times e Characters occurring 4 times h r u d l t
Characters occurring 3 times Characters occurring 2 times a c g i k m n p s v w x y z O 1 2 3 4 5
Characters occurring 1 times b f j q B D F J L Q T 0 6 7 8 9 Characters not found in the input A
C E G H I K M N P R S U V W X Y Z What You Need To Do Create a directory project3 on
your machine. In that directory, create a file named contents.c In contents. c, write the code
needed to find out what characters exist in the input. Make sure that you: o Have a header block
of comments that includes your name and a brief overview of the program. Read from standard
input until you hit end-of-fil o Prints the expected output in a clear, legible format Hint #1: There
are some good built-in character functions in ctype.h that make coding easier. Make sure you
understand the functions isdigit and isupper and islower and ispunct. Hint #2: You can use an
array or arrays to count the number of times you see each printable character Initialize each
element to zero and increment a given location when you see that letter) To test your program
with various inputs, you can redirect input so that it comes from a file instead of the keyboard.
As an example, if you wanted to see what the contents of your contents.c file was, you would
type the command /a.out contents .c (using a.exe instead of a.out in Windows
Solution
#include
#include
#include
#include
#include
int len = 0;
int sp = 0;
int lwrcaseCount = 0;
int uprcaseCount = 0;
int digitCount = 0;
int specialCount = 0;
char data[200];
int frequency[84];
int sortFrequency[84][2];
char string[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-
./:;<=>?@[/]^_`{|}~";
//printf(" ");
//To sort based on frequency of characters
/*void sort()
{
int max, loc, temp, x, y;
//Loops till end - 1 position of the frequency array
for(x = 0; x <= 84 - 1; x++)
{
//Initializes the max to the x position of the frequency array assuming it as maximum
max = frequency[x];
//Initializes of loc to x assuming location x contains the maximum value
loc = x;
//Loops through x + 1 to length - 1 of frequency array
for(y = x + 1; y <= 95 -1; y++)
{
//If current position of the frequency of the array is greater than the max
//then update the max with the current value of frequency and update the loc
if(frequency[y] > max)
{
max = frequency[y];
loc = y;
}//end of if
}//end of for loop
//If loc is not x then swap
if(loc != x)
{
temp = frequency[x];
frequency[x] = frequency[loc];
frequency[loc] = temp;
}//end of if
//Store the location of the maximum value in the zero column position of row x
sortFrequency[x][0]= loc;
//Store the maximum value in the first column position of row x
sortFrequency[x][1] = max;
}//end of for loop
}//end of function*/
void sort()
{
for(int i = 0; i < 84; i++)
{
sortFrequency[i][0] = i;
sortFrequency[i][1] = frequency[i];
}
for(int i = 0; i < 84-1; i++)
for(int j = 0; j < 84-i-1; j++)
if(sortFrequency[j][1] < sortFrequency[j+1][1])
{
int temp = sortFrequency[j][1];
sortFrequency[j][1] = sortFrequency[j+1][1];
sortFrequency[j+1][1] = temp;
temp = sortFrequency[j][0];
sortFrequency[j][0] = sortFrequency[j+1][0];
sortFrequency[j+1][0] = temp;
}
}
//To count frequency of each character
void frequencyCount()
{
int c, d;
//Loops till the length of the inputed data
for(c = 0; c < len; c++)
{
//Loops from 33 to 126 which is the ascii values of required characters range
for(d = 0; d < 84; d++)
{
//If the data in the current position is equal to the acii value
if(data[c] == string[d])
//Frequency 0 position is equal to 33 ascii.
//So 33 is deducted
frequency[d]++;
}//end of for loop
}//end of for loop
}//End of function
//Initializes the frequency array to zero
void initialize()
{
int c;
for(c = 0; c < 84; c++)
frequency[c] = 0;
}
//Read the file which contains data
void readFile()
{
//File pointer created
FILE *fptr;
char ch;
//File opened in read mode
fptr = fopen("Data1.txt", "r");
//If fptr is null show error message and terminate
if (fptr == NULL)
{
printf("Cannot open file  ");
exit(0);
}//end of if

More Related Content

Similar to So I am writing a CS code for a project and I keep getting cannot .pdf

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework HelpC++ Homework Help
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxgordienaysmythe
 
Input output functions
Input output functionsInput output functions
Input output functionshyderali123
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013ericupnorth
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programmingIcaii Infotech
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallySean Cribbs
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdfsrxerox
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogramprincepavan
 

Similar to So I am writing a CS code for a project and I keep getting cannot .pdf (20)

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Array Cont
Array ContArray Cont
Array Cont
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Input output functions
Input output functionsInput output functions
Input output functions
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
7 functions
7  functions7  functions
7 functions
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
 
Funções, Scanf, EOF
Funções, Scanf, EOFFunções, Scanf, EOF
Funções, Scanf, EOF
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 

More from ezonesolutions

hi need help with this question, ignore the circles (f) Indicate .pdf
hi need help with this question, ignore the circles (f) Indicate .pdfhi need help with this question, ignore the circles (f) Indicate .pdf
hi need help with this question, ignore the circles (f) Indicate .pdfezonesolutions
 
Explain TWO examples of fungal interactions with other speciesSo.pdf
Explain TWO examples of fungal interactions with other speciesSo.pdfExplain TWO examples of fungal interactions with other speciesSo.pdf
Explain TWO examples of fungal interactions with other speciesSo.pdfezonesolutions
 
DNA replicationTranscriptionTranslationPurposeWhere it occur.pdf
DNA replicationTranscriptionTranslationPurposeWhere it occur.pdfDNA replicationTranscriptionTranslationPurposeWhere it occur.pdf
DNA replicationTranscriptionTranslationPurposeWhere it occur.pdfezonesolutions
 
Does Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdf
Does Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdfDoes Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdf
Does Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdfezonesolutions
 
continuous, analytic, differentiableWhat is the relationship betwe.pdf
continuous, analytic, differentiableWhat is the relationship betwe.pdfcontinuous, analytic, differentiableWhat is the relationship betwe.pdf
continuous, analytic, differentiableWhat is the relationship betwe.pdfezonesolutions
 
Define the types of ultrasound pressure wavesSolutionUltrasoun.pdf
Define the types of ultrasound pressure wavesSolutionUltrasoun.pdfDefine the types of ultrasound pressure wavesSolutionUltrasoun.pdf
Define the types of ultrasound pressure wavesSolutionUltrasoun.pdfezonesolutions
 
Consider the current national debate about the revelation that top g.pdf
Consider the current national debate about the revelation that top g.pdfConsider the current national debate about the revelation that top g.pdf
Consider the current national debate about the revelation that top g.pdfezonesolutions
 
Case Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdf
Case Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdfCase Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdf
Case Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdfezonesolutions
 
A recombinant DNA was constructed by inserting the DNA of interest i.pdf
A recombinant DNA was constructed by inserting the DNA of interest i.pdfA recombinant DNA was constructed by inserting the DNA of interest i.pdf
A recombinant DNA was constructed by inserting the DNA of interest i.pdfezonesolutions
 
A conductor of length l lies along the x axis with current I in the +.pdf
A conductor of length l lies along the x axis with current I in the +.pdfA conductor of length l lies along the x axis with current I in the +.pdf
A conductor of length l lies along the x axis with current I in the +.pdfezonesolutions
 
What are the main motives for establishing an international joint ve.pdf
What are the main motives for establishing an international joint ve.pdfWhat are the main motives for establishing an international joint ve.pdf
What are the main motives for establishing an international joint ve.pdfezonesolutions
 
9 & 10 9. The study of behavioral finance has best helped explain .pdf
9 & 10 9. The study of behavioral finance has best helped explain .pdf9 & 10 9. The study of behavioral finance has best helped explain .pdf
9 & 10 9. The study of behavioral finance has best helped explain .pdfezonesolutions
 
Will Chinas economic success continue into the foreseeable future.pdf
Will Chinas economic success continue into the foreseeable future.pdfWill Chinas economic success continue into the foreseeable future.pdf
Will Chinas economic success continue into the foreseeable future.pdfezonesolutions
 
Which of the following ions would exhibit the greatest conductivity.pdf
Which of the following ions would exhibit the greatest conductivity.pdfWhich of the following ions would exhibit the greatest conductivity.pdf
Which of the following ions would exhibit the greatest conductivity.pdfezonesolutions
 
Which fault-tolerant-like system can back up media in much the same .pdf
Which fault-tolerant-like system can back up media in much the same .pdfWhich fault-tolerant-like system can back up media in much the same .pdf
Which fault-tolerant-like system can back up media in much the same .pdfezonesolutions
 
When may a federal court hear a caseSolutionFederal Court wil.pdf
When may a federal court hear a caseSolutionFederal Court wil.pdfWhen may a federal court hear a caseSolutionFederal Court wil.pdf
When may a federal court hear a caseSolutionFederal Court wil.pdfezonesolutions
 
4) Production in the country of StockVille can be characterized by th.pdf
4) Production in the country of StockVille can be characterized by th.pdf4) Production in the country of StockVille can be characterized by th.pdf
4) Production in the country of StockVille can be characterized by th.pdfezonesolutions
 
What is the pre-order traversal sequence for the above treeSolut.pdf
What is the pre-order traversal sequence for the above treeSolut.pdfWhat is the pre-order traversal sequence for the above treeSolut.pdf
What is the pre-order traversal sequence for the above treeSolut.pdfezonesolutions
 
Show that the class P, viewed as a set of languages is closed under c.pdf
Show that the class P, viewed as a set of languages is closed under c.pdfShow that the class P, viewed as a set of languages is closed under c.pdf
Show that the class P, viewed as a set of languages is closed under c.pdfezonesolutions
 
Related to Making the Connection] In the court case over whether any.pdf
Related to Making the Connection] In the court case over whether any.pdfRelated to Making the Connection] In the court case over whether any.pdf
Related to Making the Connection] In the court case over whether any.pdfezonesolutions
 

More from ezonesolutions (20)

hi need help with this question, ignore the circles (f) Indicate .pdf
hi need help with this question, ignore the circles (f) Indicate .pdfhi need help with this question, ignore the circles (f) Indicate .pdf
hi need help with this question, ignore the circles (f) Indicate .pdf
 
Explain TWO examples of fungal interactions with other speciesSo.pdf
Explain TWO examples of fungal interactions with other speciesSo.pdfExplain TWO examples of fungal interactions with other speciesSo.pdf
Explain TWO examples of fungal interactions with other speciesSo.pdf
 
DNA replicationTranscriptionTranslationPurposeWhere it occur.pdf
DNA replicationTranscriptionTranslationPurposeWhere it occur.pdfDNA replicationTranscriptionTranslationPurposeWhere it occur.pdf
DNA replicationTranscriptionTranslationPurposeWhere it occur.pdf
 
Does Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdf
Does Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdfDoes Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdf
Does Microsoft directly disclose LinkedIn revenue for 2016 Explain .pdf
 
continuous, analytic, differentiableWhat is the relationship betwe.pdf
continuous, analytic, differentiableWhat is the relationship betwe.pdfcontinuous, analytic, differentiableWhat is the relationship betwe.pdf
continuous, analytic, differentiableWhat is the relationship betwe.pdf
 
Define the types of ultrasound pressure wavesSolutionUltrasoun.pdf
Define the types of ultrasound pressure wavesSolutionUltrasoun.pdfDefine the types of ultrasound pressure wavesSolutionUltrasoun.pdf
Define the types of ultrasound pressure wavesSolutionUltrasoun.pdf
 
Consider the current national debate about the revelation that top g.pdf
Consider the current national debate about the revelation that top g.pdfConsider the current national debate about the revelation that top g.pdf
Consider the current national debate about the revelation that top g.pdf
 
Case Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdf
Case Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdfCase Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdf
Case Study UrolithiasisCase PresentationDaniel, a thirty-two ye.pdf
 
A recombinant DNA was constructed by inserting the DNA of interest i.pdf
A recombinant DNA was constructed by inserting the DNA of interest i.pdfA recombinant DNA was constructed by inserting the DNA of interest i.pdf
A recombinant DNA was constructed by inserting the DNA of interest i.pdf
 
A conductor of length l lies along the x axis with current I in the +.pdf
A conductor of length l lies along the x axis with current I in the +.pdfA conductor of length l lies along the x axis with current I in the +.pdf
A conductor of length l lies along the x axis with current I in the +.pdf
 
What are the main motives for establishing an international joint ve.pdf
What are the main motives for establishing an international joint ve.pdfWhat are the main motives for establishing an international joint ve.pdf
What are the main motives for establishing an international joint ve.pdf
 
9 & 10 9. The study of behavioral finance has best helped explain .pdf
9 & 10 9. The study of behavioral finance has best helped explain .pdf9 & 10 9. The study of behavioral finance has best helped explain .pdf
9 & 10 9. The study of behavioral finance has best helped explain .pdf
 
Will Chinas economic success continue into the foreseeable future.pdf
Will Chinas economic success continue into the foreseeable future.pdfWill Chinas economic success continue into the foreseeable future.pdf
Will Chinas economic success continue into the foreseeable future.pdf
 
Which of the following ions would exhibit the greatest conductivity.pdf
Which of the following ions would exhibit the greatest conductivity.pdfWhich of the following ions would exhibit the greatest conductivity.pdf
Which of the following ions would exhibit the greatest conductivity.pdf
 
Which fault-tolerant-like system can back up media in much the same .pdf
Which fault-tolerant-like system can back up media in much the same .pdfWhich fault-tolerant-like system can back up media in much the same .pdf
Which fault-tolerant-like system can back up media in much the same .pdf
 
When may a federal court hear a caseSolutionFederal Court wil.pdf
When may a federal court hear a caseSolutionFederal Court wil.pdfWhen may a federal court hear a caseSolutionFederal Court wil.pdf
When may a federal court hear a caseSolutionFederal Court wil.pdf
 
4) Production in the country of StockVille can be characterized by th.pdf
4) Production in the country of StockVille can be characterized by th.pdf4) Production in the country of StockVille can be characterized by th.pdf
4) Production in the country of StockVille can be characterized by th.pdf
 
What is the pre-order traversal sequence for the above treeSolut.pdf
What is the pre-order traversal sequence for the above treeSolut.pdfWhat is the pre-order traversal sequence for the above treeSolut.pdf
What is the pre-order traversal sequence for the above treeSolut.pdf
 
Show that the class P, viewed as a set of languages is closed under c.pdf
Show that the class P, viewed as a set of languages is closed under c.pdfShow that the class P, viewed as a set of languages is closed under c.pdf
Show that the class P, viewed as a set of languages is closed under c.pdf
 
Related to Making the Connection] In the court case over whether any.pdf
Related to Making the Connection] In the court case over whether any.pdfRelated to Making the Connection] In the court case over whether any.pdf
Related to Making the Connection] In the court case over whether any.pdf
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

So I am writing a CS code for a project and I keep getting cannot .pdf

  • 1. So I am writing a CS code for a project and I keep getting "cannot open file" I know I put it into my code, but I don't know why it won't execute after i input ./a.out I put in gcc -Wall contents3.c and no errors or warnings pop up. So I figure everything is working right. But after that, I get "Cannot open file". So I am wondering what I can do to get this settled out properly. I am putting the outcome of the project and my code. Please someone help me! #include #include #include #include #include #include int len = 0; int sp = 0; int lwrcaseCount = 0; int uprcaseCount = 0; int digitCount = 0; int specialCount = 0; char data[200]; int frequency[84]; int sortFrequency[84][2]; char string[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,- ./:;<=>?@[/]^_`{|}~"; //printf(" "); //To sort based on frequency of characters /*void sort() { int max, loc, temp, x, y; //Loops till end - 1 position of the frequency array for(x = 0; x <= 84 - 1; x++) { //Initializes the max to the x position of the frequency array assuming it as maximum max = frequency[x]; //Initializes of loc to x assuming location x contains the maximum value loc = x;
  • 2. //Loops through x + 1 to length - 1 of frequency array for(y = x + 1; y <= 95 -1; y++) { //If current position of the frequency of the array is greater than the max //then update the max with the current value of frequency and update the loc if(frequency[y] > max) { max = frequency[y]; loc = y; }//end of if }//end of for loop //If loc is not x then swap if(loc != x) { temp = frequency[x]; frequency[x] = frequency[loc]; frequency[loc] = temp; }//end of if //Store the location of the maximum value in the zero column position of row x sortFrequency[x][0]= loc; //Store the maximum value in the first column position of row x sortFrequency[x][1] = max; }//end of for loop }//end of function*/ void sort() { for(int i = 0; i < 84; i++) { sortFrequency[i][0] = i; sortFrequency[i][1] = frequency[i]; } for(int i = 0; i < 84-1; i++) for(int j = 0; j < 84-i-1; j++) if(sortFrequency[j][1] < sortFrequency[j+1][1]) { int temp = sortFrequency[j][1];
  • 3. sortFrequency[j][1] = sortFrequency[j+1][1]; sortFrequency[j+1][1] = temp; temp = sortFrequency[j][0]; sortFrequency[j][0] = sortFrequency[j+1][0]; sortFrequency[j+1][0] = temp; } } //To count frequency of each character void frequencyCount() { int c, d; //Loops till the length of the inputed data for(c = 0; c < len; c++) { //Loops from 33 to 126 which is the ascii values of required characters range for(d = 0; d < 84; d++) { //If the data in the current position is equal to the acii value if(data[c] == string[d]) //Frequency 0 position is equal to 33 ascii. //So 33 is deducted frequency[d]++; }//end of for loop }//end of for loop }//End of function //Initializes the frequency array to zero void initialize() { int c; for(c = 0; c < 84; c++) frequency[c] = 0; } //Read the file which contains data void readFile() { //File pointer created
  • 4. FILE *fptr; char ch; //File opened in read mode fptr = fopen("Data1.txt", "r"); //If fptr is null show error message and terminate if (fptr == NULL) { printf("Cannot open file "); exit(0); }//end of if //read the first character from the file ch = fgetc(fptr); //Loops till end of file while (ch != EOF) { //Stores the character in data array data[len++] = ch; //reads another character from the file ch = fgetc(fptr); }//end of while //close file fclose(fptr); }//End of method //Display the required information void dispData() { int c; //Displays the file contents printf(" Entered Data "); for(c = 0; c < len; c++) printf("%c", data[c]); printf(" %d characters", len - sp); printf(" lowercase = %d and ", lwrcaseCount); printf("uppercase = %d and ", uprcaseCount); printf("digit = %d", digitCount); printf(" and special = %d ", specialCount);
  • 5. for(c = 0; c < 84; c++) { if(c == 0 || sortFrequency[c][1] != sortFrequency[c-1][1]) printf(" Characters occurring %d times : ", sortFrequency[c][1]); printf("%c ", string[sortFrequency[c][0]]); } /*for(c = 0; c < 95; c++) { if(sortFrequency[c][1] != 0) printf(" Character %c occurs %d Times ", sortFrequency[c][0]+33, sortFrequency[c][1]); }//end of for printf(" Characters not found in input: "); for(c = 0; c < 95; c++) { if(sortFrequency[c][1] == 0) //printf(" Character %c occurs %d Times ", sortFrequency[c][0]+33, sortFrequency[c][1]); printf("%c ", sortFrequency[c][0]); }//end of for*/ printf(" "); }//end of function //Counts lowercase, uppercase, digits, special characters and total characters void count() { int c; for(c = 0; c < len; c++) { if(islower(data[c])) lwrcaseCount++; else if (isupper(data[c])) uprcaseCount++; else if (isdigit(data[c])) digitCount++; else if (ispunct(data[c])) specialCount++; else sp++;
  • 6. }//end of for }//end of function //Main function int main() { //Calls the methods initialize(); readFile(); count(); frequencyCount(); //dispData(); sort(); dispData(); return 0; } Project overview: Ever wonder what is in a file? Ever wonder how many times each character actually occurs in the file? Probably not most people never think of things like that. This program takes an input source and tells the user what characters that source contains. It does not worry about whitespace (spaces, tabs, newlines) but instead focuses on the printable characters. These include: 26 upper-case letters, A-Z and 26 lower-case letters, a and 10 digits, 0-9 32 special characters: "#$S&' C [V1 This program reads from standard input until end-of-file. Once it hits end-of-file, it tells the user what characters it saw, ordered from the most-occurring character down to the characters that it did not see. As an example, if the user entered the input below (shown in re the program generates the output shown in blue The Quick Brown Fox Jumps over the Lazy Old Dog 123456789012345 the quick brown fox jumps over the lazy old dog 105 characters lower case 67 and uppercase 9 and digit-15 and special 14 Characters occurring 8 times o Characters occurring 6 times e Characters occurring 4 times h r u d l t Characters occurring 3 times Characters occurring 2 times a c g i k m n p s v w x y z O 1 2 3 4 5 Characters occurring 1 times b f j q B D F J L Q T 0 6 7 8 9 Characters not found in the input A C E G H I K M N P R S U V W X Y Z What You Need To Do Create a directory project3 on your machine. In that directory, create a file named contents.c In contents. c, write the code needed to find out what characters exist in the input. Make sure that you: o Have a header block of comments that includes your name and a brief overview of the program. Read from standard input until you hit end-of-fil o Prints the expected output in a clear, legible format Hint #1: There are some good built-in character functions in ctype.h that make coding easier. Make sure you understand the functions isdigit and isupper and islower and ispunct. Hint #2: You can use an array or arrays to count the number of times you see each printable character Initialize each
  • 7. element to zero and increment a given location when you see that letter) To test your program with various inputs, you can redirect input so that it comes from a file instead of the keyboard. As an example, if you wanted to see what the contents of your contents.c file was, you would type the command /a.out contents .c (using a.exe instead of a.out in Windows Solution #include #include #include #include #include int len = 0; int sp = 0; int lwrcaseCount = 0; int uprcaseCount = 0; int digitCount = 0; int specialCount = 0; char data[200]; int frequency[84]; int sortFrequency[84][2]; char string[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,- ./:;<=>?@[/]^_`{|}~"; //printf(" "); //To sort based on frequency of characters /*void sort() { int max, loc, temp, x, y; //Loops till end - 1 position of the frequency array for(x = 0; x <= 84 - 1; x++) { //Initializes the max to the x position of the frequency array assuming it as maximum max = frequency[x]; //Initializes of loc to x assuming location x contains the maximum value loc = x;
  • 8. //Loops through x + 1 to length - 1 of frequency array for(y = x + 1; y <= 95 -1; y++) { //If current position of the frequency of the array is greater than the max //then update the max with the current value of frequency and update the loc if(frequency[y] > max) { max = frequency[y]; loc = y; }//end of if }//end of for loop //If loc is not x then swap if(loc != x) { temp = frequency[x]; frequency[x] = frequency[loc]; frequency[loc] = temp; }//end of if //Store the location of the maximum value in the zero column position of row x sortFrequency[x][0]= loc; //Store the maximum value in the first column position of row x sortFrequency[x][1] = max; }//end of for loop }//end of function*/ void sort() { for(int i = 0; i < 84; i++) { sortFrequency[i][0] = i; sortFrequency[i][1] = frequency[i]; } for(int i = 0; i < 84-1; i++) for(int j = 0; j < 84-i-1; j++) if(sortFrequency[j][1] < sortFrequency[j+1][1]) { int temp = sortFrequency[j][1];
  • 9. sortFrequency[j][1] = sortFrequency[j+1][1]; sortFrequency[j+1][1] = temp; temp = sortFrequency[j][0]; sortFrequency[j][0] = sortFrequency[j+1][0]; sortFrequency[j+1][0] = temp; } } //To count frequency of each character void frequencyCount() { int c, d; //Loops till the length of the inputed data for(c = 0; c < len; c++) { //Loops from 33 to 126 which is the ascii values of required characters range for(d = 0; d < 84; d++) { //If the data in the current position is equal to the acii value if(data[c] == string[d]) //Frequency 0 position is equal to 33 ascii. //So 33 is deducted frequency[d]++; }//end of for loop }//end of for loop }//End of function //Initializes the frequency array to zero void initialize() { int c; for(c = 0; c < 84; c++) frequency[c] = 0; } //Read the file which contains data void readFile() { //File pointer created
  • 10. FILE *fptr; char ch; //File opened in read mode fptr = fopen("Data1.txt", "r"); //If fptr is null show error message and terminate if (fptr == NULL) { printf("Cannot open file "); exit(0); }//end of if