[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Hvad skal jeg linke?



Prøv nedenstående - der kører!
(Jeg behøver vel ikke fortælle hvad der mangler i dit oprindelige
program?)

#include<stdio.h>
#include<sys/time.h>
#include<unistd.h>
#include<stdlib.h>

main()
   {
  struct timeval * t1; 
  struct timeval * t2;
  long secs;
  long usecs;
  t1 = (struct timeval *) malloc(sizeof(struct timeval));
  t2 = (struct timeval *) malloc(sizeof(struct timeval));
  gettimeofday(t1,NULL);
// ting der tager tid
  gettimeofday(t2,NULL);
  secs = t2->tv_usec - t1->tv_usec < 0 ? t2->tv_sec - t1->tv_sec -
1 : t2->tv_sec - t1->tv_sec;
  usecs = (t2->tv_usec - t1->tv_usec < 0 ? 1000000 : 0) +
t2->tv_usec - t1->tv_usec;
  printf("Tid: %i sekunder og %i mikrosekunder\n",secs, usecs);
  free(t1);
  free(t2);
  return 0;
   }

/Egon
Christian Hemmingsen wrote:
> 
> Anders Melchiorsen wrote:
> 
> > > av2.c: In function `main':
> > > av2.c:14: `timeval' undeclared (first use in this function)
> > > av2.c:14: (Each undeclared identifier is reported only once
> > > av2.c:14: for each function it appears in.)
> >
> > Jeg tror, du skal skrive "struct timeval" i stedet for "timeval" i
> > linie 14.
> 
> Jeg prøvede men det virkede desværre ikke. Jeg må hellere vise lidt
> kode:
> 
> #include<stdio.h>
> #include<sys/time.h>
> #include<unistd.h>
> #include<stdlib.h>
> // ....
>   timeval* t1; //linje 14
>   timeval* t2;
>   t1 = (timeval*)malloc(sizeof(timeval));
>   t2 = (timeval*)malloc(sizeof(timeval));
>   gettimeofday(t1,NULL);
> // ting der tager tid
>   gettimeofday(t2,NULL);
>   long secs = t2->tv_usec - t1->tv_usec < 0 ? t2->tv_sec - t1->tv_sec -
> 1 : t2->tv_sec - t1->tv_sec;
>   long usecs = (t2->tv_usec - t1->tv_usec < 0 ? 1000000 : 0) +
> t2->tv_usec - t1->tv_usec;
>   printf("Tid: %i sekunder og %i mikrosekunder\n",secs, usecs);
>   free(t1);
>   free(t2);
> // .....
> 
> Prøver jeg som Anders foreslår at tilføje struct i linje 14 og 15,
> brokker den sig i linje 16 med samme fejl, og der hjælper det ikke at
> tilføje struct.
> Laver jeg en ldd på mit C++ program ser jeg det linker libm, men det
> hjælper ikke at tilføje -lm når jeg kompilerer.
> Jeg er lidt på bar bund her :(
> Håber nogen kan hjælpe, ellers må jeg jo bare lave det som C++.
> 
> VH
> Christian Hemmingsen

-- 
* Talura ApS      * Phone: +45 43 52 50 00 *
* Baldershøj 24 B * mailto:sslug@sslug  *
* DK-2635  Ishøj  * http://www.talura.dk   *


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *