Thread: please help me!!

  1. #1
    Registered User
    Join Date
    Jul 2007

    Unhappy please help me!!

    I've been working on the code below for some time now and I just can't fix it,
    can some one please help me.

    basically I want to get an input file and a search word as command line arguments and I want to output the number of occurrence of that word in the file.

    #include <stdio.h>
    #include <ctype.h>
    #include <stdafx.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <string.h>
    int _tmain(int argc, _TCHAR* argv[])
    	char buff[1000]={0},
    	     int i=0;       
             int n = 0;
    		 int j =0;
      if ( argc > 2 ) {
        FILE *fp = fopen( argv[1], "r" );
        if ( fp == NULL ) perror ("error openning file");
    	else {
    		 while ( fgets( tempStr, sizeof tempStr, fp ) != NULL ) {
    		 tokenPtr = strtok (buff,",. \n\t!-");
    		 while (tokenPtr != NULL) {
    			 for (i=2;i<3;i++) {
    				 if (strcmp (tokenPtr,argv[i]) == 0) {
    			 tokenPtr = strtok (NULL,",. \n\t!-");
    		 printf( "%8s%15s\n", "Search Word ", "Occurrences" );
    		 printf( "%4s%15d", argv[i],n,  '\n' );
    		 printf( "\n" );
    		 fclose (fp);
    	return 0;
    it gives me this error when try to compile it:
    fatal error C1075: end of file found before the left brace '{' at 'myprog4.cpp(10)' was matched

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    First off, take note of the announcements up towards the top of the page:
    3. Do not put URGENT!, or NEED HELP NOW, etc. in your title; it will not make people look at it any faster. Doing this makes many old time helpers on this board not look at the post at all.
    Your post title qualifies under this.

    Now, on to your question. Purely on the basis of the error message reported, and not dealing with any other potential errors, it is apparent that there is an unmatched brace somewhere in your code. Better indentation helps detect this in many cases. You have 9 occurrences of opening braces and only 8 of closing braces in your code... find the discrepancy.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jul 2007
    I'm sorry I'm new to this forum,
    thanks for the help

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Here's a tip: When you type an opening brace (or quote, or parenthesis or start of comment), type the matching closer at the same time (eg ""), then move the cursor between them and add the content you want (eg "hello").

    They'll never be mis-matched, and they'll always be in the right place.

    Some auto-completing code editors can be made to do this for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed