Please help! - Who find mistake in the program??

This is a discussion on Please help! - Who find mistake in the program?? within the C++ Programming forums, part of the General Programming Boards category; Hi all. I'm from Poland so sorry for my English, but I think you'll unterstand my thread. In the University ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    2

    Please help! - Who find mistake in the program??

    Hi all. I'm from Poland so sorry for my English, but I think you'll unterstand my thread.

    In the University my teacher wrote the program in Visual Studio, in school this program working, but in the home my teacher saw that this program working not good. We have to find the mistake in the program and send to my teacher the mail with the solution. But we don't know where is the mistake so I must say to You HELP!

    This is code this programs

    [code]Witam. Od wykładowcy na studiach grupa otrzymała maila postaci:

    Code:
    // list.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <cstdio>
    
    using namespace std;
    
    struct list_node
    {
       int number;
       list_node *next;
    };
    
    void add_element(list_node *list, list_node *current)
    {
       list_node *node = list->next;
    
       list->next = current;
       current->next = node;
    }
    
    void remove_element(list_node *list, int number)
    {
       while(list->next)
       {
          if(list->next->number == number)
          {
             list_node *node = list->next;
             list->next = list->next->next;
             delete node;
          }
          else
          {
             list = list->next;
          }
       }
    }
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
       list_node *list = new list_node;
       list->number = -1;
       list->next = 0;
    
       // dodawanie element�w do listy (sprawdzi�, czy elementy dodawane s� na jej pocz�tek, czy na koniec)
       for(int i = 0; i < 10; ++i)
       {
          list_node *current = new list_node;
          current->number = i;
    
          add_element(list, current);
       }
       // usuwanie element�w z listy o zadanym numerze
       int to_delete[] = {7, 0, 1, 9, 5, 5, 3, 145};
       for(int i = 0; i < sizeof(to_delete)/sizeof(int); ++i)
       {
          remove_element(list, to_delete[i]);
       }
    
       // wy�wietlenie pozosta�ych element�w listy
       while(list)
       {
          printf("Element nr %i\n", list->number);
          list = list->next;
       }
       return 0;
    }
    Thanks for your help. Cy'a

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Have you compiled it? This could be one problem

    Code:
    Untitled1.cpp ISO C++ forbids declaration of `argv' with no type
    I'm just trying to be a better person - My Name Is Earl

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,888
    It's not helpful to dump code on us without telling us the compile errors (and warnings!).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    2
    Please read my thread again, i wrote that this program working but not good, so program compile ok i don't have warnings, but program working NOT GOOD.

    Please help...

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    How does your program not work correctly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Please find an error in my noob program
    By alexpos in forum C Programming
    Replies: 2
    Last Post: 10-23-2005, 03:55 PM
  3. my program can't find "allegro.h"
    By Leeman_s in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2002, 09:05 PM
  4. Replies: 4
    Last Post: 08-15-2002, 12:35 PM
  5. Replies: 2
    Last Post: 05-10-2002, 05:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21