d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Iso-help With C Programming Homework > Ft-fg
Add Reply New Topic New Poll
Member
Posts: 11,499
Joined: Sep 5 2011
Gold: 11,376.21
Feb 13 2013 10:12am
Will gladly offer fg if anybody would be willing to help me with this assignment. My professor is really intelligent but is a horrible teacher. I've been struggling with the class and wondering if anybody has advice on taking notes/what to pay attention to etc in intro level c programming. My professor doesn't really teach he just flies through everything faster than I can even take notes and doesn't really explain in depth of why we're using certain functions etc.




here is the assignment:
http://cs.indstate.edu/CS201/prob09.pdf
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Feb 13 2013 11:05am
I'll do this for you. Give me like 30 minutes or so
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Feb 13 2013 12:10pm
Code
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <conio.h>

int main()
{
int i, counter = 0;
int max_occurred = 0;
int times_occurred = 0;
char c;
 
char * charArray = new char[5000];

FILE * file = fopen("misc.txt", "rt");

if(file == NULL)
{
 printf("Error opening file!");
}
else
{
 do
 {
  i = fgetc(file);
  charArray[counter] = i;

  counter++;
 }while(i != EOF);

 fclose(file);
}

for(int j = 0; j < counter - 1; j++)
{
 for(int jj = 0; jj < counter - 1; jj++)
 {
  if(charArray[j] == charArray[jj])
  {
   times_occurred++;
  }
 }

 if(times_occurred > max_occurred)
 {
  max_occurred = times_occurred;
  c = charArray[j];
 }
 
 times_occurred = 0;
}

printf("%i %i %c", max_occurred, (int)c, c);

_getch();


  delete[] charArray;
return 0;
}


This post was edited by SelfTaught on Feb 13 2013 12:13pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll