473,779 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where's the mistake???

compiler says: function undeclared how come???
help!
#include<stdio. h>
#include<stdlib .h>
#include<time.h >

struct lista{
int element;
struct lista *next;
}*pocetak;

main()
{
struct lista *q, *nova;
int i;
pocetak=NULL;
srand(time(NULL ));
for(i=0;i<5;i++ )
{
q=(struct lista*) mallloc(sizeof( struct lista));
q->element=rand() %100;
pocetak=q;
q->next=NULL;
}
q=pocetak;
printf("Nasumic ni brojevi:\n");
while(q!=NULL)
{
printf("\n%d",q->element);
q=q->next;
}
printf("\nNaopa ko:\n");

return 0;
}
Nov 14 '05
25 1532
Heh, been there, done that several times myself, unfortunately.


I don't see it ... :-(
Nov 14 '05 #11
Oops, I guess my finger kinda stuck ...
sorry for that ...

all well ...

Nov 14 '05 #12
.... and thanks
Nov 14 '05 #13
One of your mistakes is in the following line:
nova=(struct lista*) mallloc(sizeof( struct lista));


- Dario (the compiler and/or linker already told that?)
Nov 14 '05 #14
I need to write a program that generates 5 random numbers and puts them into
a linked list. (Print the list) From that list it forms another list in a
way if the arrangement of elements in the first one was 5 8 3 1 in the new
one it should be
1 3 8 5 (print the new list)

where's the error now ??

#include<stdio. h>
#include<stdlib .h>
#include<time.h >

struct lista{
int element;
struct lista *next;
}*pocetak;

main()
{
struct lista *q, *nova;
int i;
pocetak=NULL;
srand(time(NULL ));
for(i=0;i<5;i++ )
{
q=(struct lista*) malloc(sizeof(s truct lista));
q->element=rand() %100;
pocetak=q;
q->next=NULL;
}
q=pocetak;
printf("Nasumic ni brojevi:\n");
while(q!=NULL)
{
printf("\n%d",q->element);
q=q->next;
}

q=pocetak;
for(i=0;i<5;i++ )
{
nova=(struct lista*) malloc(sizeof(s truct lista));
nova->element=poceta k+(5-i)*(sizeof(stru ct lista));
pocetak=nova;
nova->next=NULL;
}
nova=pocetak;
printf("\nNaopa ko:\n");
while(nova!=NUL L)
{
printf("\n%d",n ova->element);
nova=nova->next;
}
system("pause") ;
return 0;
}
Nov 14 '05 #15
Nikola wrote:
compiler says: function undeclared how come??? q=(struct lista*) mallloc(sizeof( struct lista));

^^^^^^^
spelling error

Nov 14 '05 #16
Nikola wrote:
I need to write a program that generates 5 random numbers and puts them into
a linked list. (Print the list) From that list it forms another list in a
way if the arrangement of elements in the first one was 5 8 3 1 in the new
one it should be
1 3 8 5 (print the new list)

where's the error now ??
[...]
q=(struct lista*) malloc(sizeof(s truct lista));
q->element=rand() %100;
pocetak=q;
q->next=NULL;


Here.

An excellent way to teach yourself how to manipulate
links in data structures is to draw "before and after"
diagrams of the operation you want to perform. Study the
diagrams to see which links must change, and to what.

--
Er*********@sun .com

Nov 14 '05 #17
> > q=(struct lista*) malloc(sizeof(s truct lista));
q->element=rand() %100;
pocetak=q;
q->next=NULL;


Here.


ok I rewrote the code, no mistakes but it still doesn't work ...
#include<stdio. h>
#include<stdlib .h>
#include<time.h >

struct lista{
int element;
struct lista *next;
}*pocetak1,*poc etak2;

main()
{
struct lista *q, *nova;
int i;
pocetak1=NULL;
srand(time(NULL ));
for(i=0;i<5;i++ )
{
q=(struct lista*) malloc(sizeof(s truct lista));
q->element=rand() %100;
q->next=pocetak 1;
pocetak1=q;
}
q=pocetak1;
printf("Random numbers:\n");
while(q!=NULL)
{
printf("\n%d",q->element);
q=q->next;
}
printf("\nOther way round:\n");
q=pocetak1;
for(i=0;i<5;i++ )
{
nova=(struct lista*) malloc(sizeof(s truct lista));
nova->element=(q+( 5-i)*sizeof(struc t lista))->element;
q=q->next;
nova=nova->next;
nova->next=pocetak 2;
pocetak2=nova;
}
nova=pocetak2;
while(nova!=NUL L)
{
printf("\n%d",n ova->element);
nova=nova->next;
}
system("pause") ;
return 0;
}
Nov 14 '05 #18
Nikola wrote:

I took a wild shot guessing dtat you have a compiler :-)


For the most part, I don't go and run every piece of code posted here.
Most often, when the person asking the question gives us complete
information, the problem can be solved by inspection.

Had you pointed to the correct error line, we could have pointed out
that you mispelled the function name. No need to run it.


Brian Rodenborn
Nov 14 '05 #19
Nikola <az*****@inet.h r> wrote:
ok I rewrote the code, no mistakes but it still doesn't work ... #include<stdio. h>
#include<stdlib .h>
#include<time.h > struct lista{
int element;
struct lista *next;
}*pocetak1,*poc etak2;
There doesn't seem to be any good reason to make these variables
globals, so why don't you define them within main()?
main()
Better make that

int main()

or

int main(void)

in order to be prepared for C99-compliant compilers that don't
allow functions without an explicit return type anymore.
{
struct lista *q, *nova;
int i;
pocetak1=NULL;
srand(time(NULL ));
for(i=0;i<5;i++ )
{
q=(struct lista*) malloc(sizeof(s truct lista));
There isn't much of a good reason (well a few of the regulars here
disagree but...) for casting the return value of malloc()...
q->element=rand() %100;
I hope you're aware that this isn't a good way to restrict the range
of the random generator - the lower bits it returns usually have less
"randomness ", so its preferable to use something like

q->element = ( int ) ( 100.0 * rand( ) / ( RAND_MAX + 1.0 ) );
q->next=pocetak 1;
pocetak1=q;
}
q=pocetak1;
printf("Random numbers:\n");
while(q!=NULL)
{
printf("\n%d",q->element);
q=q->next;
}
printf("\nOther way round:\n");
q=pocetak1;
for(i=0;i<5;i++ )
{
nova=(struct lista*) malloc(sizeof(s truct lista));
nova->element=(q+( 5-i)*sizeof(struc t lista))->element;


You seem to be assuming that the elements of the first linked list
somehow are located in memory in a densely packed fashion, one after
another, with the last allocated list element being the one at the
highest memory address. That's definitely not a valid assumption
and you will probably end up with pointing to memory you don't even
own. (And even if your assumption would be correct you would need
"(4 - i)" instead of "(5 - i)"...) A linked list is _not_ an array
and malloc() is perfectly within its rights when it gives you some
memory at a lower address, possibly several megabytes away, than
it returned in the previous call.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1732
by: Paul T. Rong | last post by:
Dear all, My aim is to compact and repair current database, I got the following code from http://www.mvps.org/access/general/gen0041.htm Option Compare Database ' ***** Code Start ***** Public Sub CompactDB()
15
2252
by: Paul T. RONG | last post by:
Hello, I am making a restaurant database (it is much more complicated than I thought before!), now it comes to the last stage and I come across a problem. I will explain it in detail. In a restaurant, though rarely, but it happens, that one guy from desk1 would like to pay for bills of both desk1 and desk2 (I avoid using Access term "table"), that means the dishes that ordered seperately before by desk1 and desk2 now have to be commixed...
23
1785
by: Red Dragon | last post by:
I am self study C program student. Hope someone can help me with this problem. This program generates random numbers over a user defined range using call function I used the call function " GenRndNum". The range is 2 and 10. The problem is that I get the same 2 random numbers generated over 2 calls. I should get 2 different random numbers. Can someone please point out my mistake? Thanks Khoon.
3
14939
by: bughunter | last post by:
IMHO, statements like this is mistake typically. May be more better made this construction - I said about empty WHERE - invalid? A lot of data will saved... :-) Andy
2
1151
by: Lad | last post by:
I use the following code to sort dictionary. Olddict={'r':4,'c':1,'d':2,'e':3,'f':2} Newdict={} i = i.sort() # by val i.reverse() # Get largest first. for (val, key) in i: print key,val
20
5246
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've used various techniques ( loop unrolling, loop jamming...) and tried some matrix libraries : newmat (slow for large matrix) , STL (fast but ..not usefull) , hand coding (brain consuming...), and recently Meschach...
4
2184
by: Winston | last post by:
Where is the mistake? I want to make a simple menu. These are two pieces of two files... function ShowMenu(objeto) { is_open = document.getElementById(objeto).style.display; document.getElementById("menu_p").style.display='none'; if (is_open == 'none') { document.getElementById(objeto).style.display='block'; }
4
3571
by: | last post by:
I have learned about compartmentalizing my code base using Class Libraries. I have my common code such as my ORM framework broken out into their own Class Libraries, which are referenced as projects from my Website. I also have a common set of DLLs I use across all of my applications. It would be great if I could put all of those DLLs into their own projects, and to reference that project from various solutions. The way my solution is...
2
1217
by: Eglute | last post by:
Hello. I have a problem. I am a begginer in PHP. I wrote the code: <? $variable=5; $variable<10? {$ans="less"; echo $ans."<br>"; echo "variable=".$variable."<br>";}: {$ans="more"; echo $ans."<br>"; echo "variable =".$variable."<br>";} ?>
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.