Find the answer to your Linux question:
Results 1 to 10 of 10
I have my essentials build and all other necessary to develop a k Means for a chosen dataset, bu unfortunately can't even open the file my code is; #include <stdio.h> ...
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    5

    Question C Help On Ubuntu Latest...

    I have my essentials build and all other necessary to develop a k Means for a chosen dataset,

    bu unfortunately can't even open the file my code is;

    #include <stdio.h>

    int main()

    {
    FILE *ret;
    ret=fopen("~/CENG714/blok16_EO.txt" , "r");
    if (ret=NULL);
    (
    printf("Didn't opened\n");
    return 0;
    )
    }

    when i say on terminal it gives me;

    cc -c deneme.c:
    deneme.c: In function ‘main’:
    deneme.c:10: error: expected ‘)’ before ‘;’ token
    deneme.c:13: error: expected ‘;’ before ‘}’ token
    root:

    I can not understand what the hell does that mean... what am i suppose to do please all help me...

    Regards

  2. #2
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    #include <stdio.h>

    int main()

    {
    FILE *ret;
    ret = fopen("blok16_EO.txt", "r");
    if (ret= NULL){
    printf("**** the world!\n");
    return 0;
    }
    }

    this one worked but did not give any kind of a answer like i did or did not...

    is there a statement like " not = " so that i can check it?

    regards

  3. #3
    Linux User
    Join Date
    Jan 2006
    Posts
    414

    Thumbs up

    Try something like this:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char** argv)
    {
    	FILE *ret;
    	char file[255];
    	char* home = getenv("HOME");
    	sprintf(file,"%s/CENG714/blok16_EO.txt",home);
    	ret = fopen(file , "r");
    	if (ret == NULL) {
    		fprintf(stderr,"Didn't open\n");
    		return 0;
    	}else{
    		printf("Opened\n");
    	}
    	fclose(ret);
    	return 0;
    }
    Now compare that to your code, and spot the problems.

  4. #4
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    Quote Originally Posted by darkrose0510 View Post
    Try something like this:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char** argv)
    {
    	FILE *ret;
    	char file[255];
    	char* home = getenv("HOME");
    	sprintf(file,"%s/CENG714/blok16_EO.txt",home);
    	ret = fopen(file , "r");
    	if (ret == NULL) {
    		fprintf(stderr,"Didn't open\n");
    		return 0;
    	}else{
    		printf("Opened\n");
    	}
    	fclose(ret);
    	return 0;
    }
    Now compare that to your code, and spot the problems.
    Thank you very much;

    I have a lots of changes, can you write near to it which one means what?

    so that i can learn from the process.

    Regards

    Thanks...

  5. #5
    Linux User
    Join Date
    Jan 2006
    Posts
    414
    Here you go, all commented up.
    Code:
    #include <stdio.h>
    /* stdlib is needed for getenv() */
    #include <stdlib.h>
    
    int main(int argc, char** argv)
    {
    	/* file pointer */
    	FILE *ret;
    	/* file name */
    	char file[255];
    	/* get the users home directory */
    	char* home = getenv("HOME");
    	/* put the complete home/filename path into file variable */
    	sprintf(file,"%s/CENG714/blok16_EO.txt",home);
    	/* open the file */
    	ret = fopen(file , "r");
    	/* if ret is null the file didn't open */
    	if (ret == NULL) {
    		/* write a message to standard error */
    		fprintf(stderr,"Didn't open\n");
    		/* exit */
    		return 0;
    	}else{
    		/* file opened successfully */
    		printf("Opened\n");
    	}
    	/* close the file */
    	fclose(ret);
    	/* exit */
    	return 0;
    }

  6. #6
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    Quote Originally Posted by hissedar View Post
    if (ret=NULL);
    It should be logical equal operator == not assignment operator =
    If you use ; after if block - its considered as empty block - if evaluation is true.

    google the term "c programming kernighan ritchie" should provide you C programming book for the beginners.

    HTH
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  7. #7
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    Thank you guys for all the help;

    can you guys tell me how to write a K means program in C, with respect to a dataset which is in text.

    I am doing my best to write something, but short time, short learning.

    Regards

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Remember, classwork help is not allowed in the forums.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    Oh... !

    ok, didn't know that sorry.

    Regards

  10. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    No problem. The best we can do for classwork type questions is to point you in a direction that will help you find the answers you need. After all, the purpose of class exercises is for you to learn how to do this stuff, and to learn how to find out where resources are that you can use without violating your school's ethical standards.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...