This is my code and under it will be autograder can someone please show me what
ID: 3728301 • Letter: T
Question
This is my code and under it will be autograder can someone please show me what is wrong with the code.
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("Enter the length of the string:");
int n,i=0;
scanf("%d",&n);//reading input
//you can modify this line
//int *a = (int *)malloc(sizeof(int)*n+2);
char *a = (char *)malloc(sizeof(char)*n);//declaration
//dynamic allcoation
printf("Enter the string:");
while(i<n)//reading string...
{
scanf("%c",(a+i));
i++;
}
char c;
printf("Enter search character:");
scanf("%c",&c);
i=0;
int count=0;
//finding character cound
while(i<n)
{
if(*(a+i)==c)count++;
i++;
}
printf("Characters found: %d ",count);
return 0;
}
autograder
Explanation / Answer
#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
// structured data type containing information on students
struct Student_data
{
// member variables
string first_name;
string last_name;
double assignment;
double exam;
double project;
};
int main()
{
// get the input file name from the user
string filename;
cout << "Enter the input filename: ";
getline(cin, filename);
string lname;
string fname;
// try to open the input file
ifstream infile{filename};
if (!infile)
{
cout << "Error: could not open input file ";
}
else
{
// get the output file name from the user
cout << "Enter the output filename: ";
getline(cin, filename);
// try to open the output file
ofstream outfile{filename};
if (!outfile)
{
cout << "Error: could not open output file ";
}
else
{
// read in the data from the input file and output it
// to the output file
// read in first line of document
infile >> lname;
infile >> fname;
}
}
cout << fname << " "<< lname <<" ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.