Thread: A for-loop as a while statement?

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    4

    Question A for-loop as a while statement?

    Hi guys,
    i'm having some troubles finishing my programm. My programm delete all files that have the same parameter.

    So here i read the files and find a specific string:


    Code:
    if (datei = fopen(filepfad, "a+"))
        {
            while (fgets(buffer, sizeof(buffer), datei)){
                vtNr = 0;
                index = 0;
                str_leng = my_strlen(buffer);
    
                //So lange das der Teil String "vtNr" nicht gefunden wird, springt der buffer an die nächste Stelle.
                //Wenn die letzte Stelle der Zeile erreicht wurde springt das Programm in die nächste Zeile.(Dokumentaiton zu fgets lesen) 
                while(!( buffer[index] == 'v' && buffer[index + 1] == 't' && buffer[index + 2] == 'N' && buffer[index + 3] == 'r') && index <= (str_leng - 3) )index++;
                
                if ( index < str_leng - 3 )    {
                    while(!(buffer[index] >= '0' && buffer[index] <= '9'))index++;
                    while(buffer[index] >= '0'  && buffer[index] <= '9')    {
                        vtNr = vtNr * 10 + chartoint(buffer[index]);
                        index++;
                    }
                    fclose(datei);
                    if ( vtNr > 999999) vtNr_vergleichen(vtNr, filepfad);
                }
            }

    In the while loop i check if the string is found, but i want that the user determined which string he is looking for. I thought do to it like something like this:

    Code:
    while( !( for(i=0 ; i < str_end ; i++) buffer[index + i] == str_looking [i]) ) index++;
    str_end is the length of the string written by the user.

    Thanks for your time .

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You can't put for loops within the condition of a while loop in that manner.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    I know that it doesn't work, but need any other idea how i can check if my programm has find the String.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    32

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help in C function with loop statement
    By [Student] in forum C Programming
    Replies: 12
    Last Post: 02-15-2011, 04:00 PM
  2. Using while loop for if statement.
    By Galens in forum C++ Programming
    Replies: 5
    Last Post: 10-03-2008, 03:14 PM
  3. if statement in while loop
    By C++Noobie in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2006, 11:38 AM
  4. For/loop statement
    By stevedawg85 in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2006, 08:03 PM
  5. explain this loop statement?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-05-2002, 02:46 AM