Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
O

Overfiend

@Overfiend
About
Posts
4
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Counting characters in a buffer
    O Overfiend

    Im trying but i need some help! because i still cant get this to work

    C / C++ / MFC c++

  • Counting characters in a buffer
    O Overfiend

    Ok im trying to count the characters that i have loaded into a buffer i have set up the following function void countchars(char *buffer, int *count) /*Counts the number of characters in the text file */ { int i,counter; char cdata; count['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; do { { for(cdata='A';cdata<='Z';cdata++) if(buffer[i]==counter[count]) { count++; } i++; } }while(buffer[i]!=EOF); } I am calling this function using the following code: countchars(buffer,cdata); printf("\nDistribution of letters in %s is:",fname); for (c='A';c<='Z';c++) { N=cdata[c]+cdata[tolower(c)]; printf("\n'%c' %4d: ",c,N); for (i=0;i

    C / C++ / MFC c++

  • Counting characters in a buffer
    O Overfiend

    Ok im trying to count the characters that i have loaded into a buffer i have set up the following function void countchars(char *buffer, int *count) /*Counts the number of characters in the text file */ { int i,counter; char cdata; count['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; do { { for(cdata='A';cdata<='Z';cdata++) if(buffer[i]==counter[count]) { count++; } i++; } }while(buffer[i]!=EOF); } I am calling this function using the following code: countchars(buffer,cdata); printf("\nDistribution of letters in %s is:",fname); for (c='A';c<='Z';c++) { N=cdata[c]+cdata[tolower(c)]; printf("\n'%c' %4d: ",c,N); for (i=0;i

    C# c++

  • Counting characters from a text file
    O Overfiend

    Hello everyone, Ok im having alot of trouble with pointers here im trying to get my head around them but it just aint working! Im trying to create a program that will load a txt file into a buffer and then count how many characters are in the text file as well as lines and words the problem is it doesnt count the characters i can get it to count the lines and words but not individual characters. The code looks like this: #include #include #define BUFSIZE 1024 #define NCHARS 256 int getfile(char *fname, char *buffer, int buflen); void countchars(char *buffer, int *count); int Nlines(char *buffer); int Nchars(char *buffer); int Nwords(char *buffer); void main(void) { char fname[100]; char buffer[BUFSIZE]; int cdata[NCHARS]; int i,N; char c; printf("EL1113 assignment 2, 2002/3."); printf("\nText file analysis program."); printf("\n\nEnter the file name: "); scanf("%s",fname); if (getfile(fname,buffer,BUFSIZE)) { printf("\n%s contains ",fname); printf("%d characters and ",Nchars(buffer)); printf("%d words in ",Nwords(buffer)); printf("%d lines.\n",Nlines(buffer)); countchars(buffer,cdata); printf("\nDistribution of letters in %s is:",fname); for (c='A';c<='Z';c++) { N=cdata[c]+cdata[tolower(c)]; printf("\n'%c' %4d: ",c,N); for (i=0;i { putchar(c); } } printf("\n"); } } int getfile(char *fname, char *buffer, int buflen) { int i; int ch; int nchars = 0; FILE *ipfile; /*clear buffer*/ for (i=0;i { buffer[i]='\0'; } /*read from file into buffer*/ ipfile=fopen(fname,"r"); /*This code basically opens a*/ /*specified text file in read mode and*/ /*assigns it to the pointer ipfile*/ /*giving it the variable name fname*/ if (ipfile==NULL) { fprintf(stderr,"\nFile %s not found.",fname); return 0; /*The fprintf statement acts just like*/ /*the printf statement*/ } else { do { ch=fgetc(ipfile); /*collecting a character from the*/ /*ipfile pointer that holds the*/ /*destination for the imported file*/ /*EOF=End Of File*/ if (ch!=EOF) { buffer[nchars]=ch; nchars++; if (nchars==buflen) { fprintf(stderr,"\nFile %s ",fname); fprintf(stderr,"too large for buffer."); fprintf(stderr,"\nRead first %d ",buflen); fprintf(stderr,"characters from %s.",fname); } } } while ((ch!=EOF)&&(nchars fclose(ipfile); /*The fclose statement simply closes the file*/ /*that you are working on when it is no longer needed*/ return 1; } } /**********************************************/ /*THIS IS TH PART THAT DOESNT WORK************

    C / C++ / MFC c++ help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups