[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Problem in one program...




do you really mean to show the data before you read it?

On Sun, 08 Aug 1999, FX wrote:
> Hi all!
> 
> I written this program, but not fuction correct! Why? This program read
> entries in /etc/passwd and add in on GList *list.
> 
> Compiling this program and look why don't function correct.
> 
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <pwd.h>
> #include <sys/types.h>
> #include <glib.h>
> 
> 
> GList *list = NULL;
> GList *listrunner = NULL;
> 
> 
> int gsa_user_read_data(void)
> {
>         struct passwd *user;
>         char tecla;
>         int i;
> 
>         for(i=0; i < 5; i++) {
>                 user = (gpointer) g_malloc (sizeof(struct passwd));
>                 
>                 user = getpwent ();
> 
>                 list = g_list_append (list, (gpointer)user);
> 
>                 printf("\nUser: %s\n", user->pw_name);
>                 printf("Home-Dir: %s\n", user->pw_dir);
>                 printf("Shell: %s\n", user->pw_shell);
>                 tecla = getchar ();
> 
>         }
> 
> }
> 
> 
> int gsa_user_show_data (void)
> {
>         struct passwd *show;
>         char tecla;
> 
>         listrunner = g_list_first (list);
>         
>         system("clear");
> 
>         while (listrunner) {
>         
>                 show = (gpointer) g_malloc (sizeof(struct passwd));
>         
>                 show = (struct passwd*)listrunner->data;
> 
>                 printf("Tamanho da lista: %d\n", g_list_length (list));
> 
>                 printf("\nUser: %s\n", show->pw_name);
>                 printf("Home-Dir: %s\n", show->pw_dir);
>                 printf("Shell: %s\n", show->pw_shell);
>                 tecla = getchar ();
>                 
>                 listrunner = g_list_next (listrunner);
>         }
> }
> 
> 
> int main()
> {
>         system ("clear");        
> 	gsa_user_show_data ();
>         gsa_user_read_data ();
> 
> }
> 
> 
> 
> Thanks,
> 
> Fabricio [FX]
> 
> P.S: Sorry my bad English! :P
> 
> 
> -- 
>          To unsubscribe: mail gtk-app-devel-list-request@redhat.com with 
>                        "unsubscribe" as the Subject.
> 
> 	Mailing list concerns should be mailed to <listmaster@redhat.com>
-- 
***********************************************************************
* Joe Barr                                    The Dweebspeak Primer   *
* joe@pjprimer.com                            http://www.pjprimer.com *
*---------------------------------------------------------------------*
*   "No," said Pooh. "Not these.  These are called mastershalums."    *
*********************************************************************** 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]