while (choice != QUIT)
    {
        choice = get_menu_choice();
        
        if (choice == 1)
        {
       while(1)//while loop that i want to break out of 
       { 
		puts("please give your archive a name and a path:\n");
		scanf("%s", &archive_name);
       
        if( create_pointer = fopen(archive_name, "r") != NULL)
        {
        printf("file already exists\n");
        continue;
        }
        else 
           
{
        create_pointer = fopen( archive_name, "ab");
        puts("archive created\n");
        
       
        puts("please select the file you want to be copied into your archive\n");
        scanf("%s",&original_file);
        open_pointer = fopen( original_file, "r+b");                                 
        original_pointer = fopen(original_file,"a+b");                            
        copy_pointer = fopen( archive_name,"a+b");
        }
        while (( n = fread(buffer,1,sizeof buffer, original_pointer)) > 0)
        {
        fwrite(buffer,1, n , copy_pointer);
    }
    if((original_pointer !=NULL) && (copy_pointer != NULL))
        {
            
        fclose(original_pointer);
        fclose(copy_pointer);
        
        fclose(open_pointer);
        printf("done..... %s  copied to  %s.\n",original_file,archive_name);
    
      
         get_menu_choice();
        }
      
        if (original_pointer == NULL)
        {
        puts("unable to open original file\n");
        }
        if (copy_pointer == NULL)
        {
        puts("unabe to open copiedied file");
       
        get_menu_choice();
    

    
        fclose(create_pointer);
    
        
        }
        //break goes hear but i get a segmentation fault error
        }

Recommended Answers

All 4 Replies

Would you care to explain a little more what the problem is? You posted several while loops -- which one(s) is giving you the problem?

i stated in the code its the while(1) loop i commented on it

It's almost certainly not a problem that's caused directly by putting a break in the while loop. It will be something to do with the many custom functions that you have in there. However, we can't see what they are at the moment.

I'm not asking you to post the whole code to your program, I don't think that would help, rather go through the lines inside the while loop one-by-one and see how far the program gets before it segfaults. Then you'll have a rough idea what the culprit is. Whatever it is, it's probably not the fault of the break .

Also, your code is a bit of a mess in terms of random carriage returns, indents, use of braces and such. It makes it much harder for people to help you.

Using while(1) amounts to while(true). Since 1 is a constant, it will never be false and the loop will go on forever unless program flow encounters a break statement. Try something like:

if(some condition is met) break;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.