Thread: Gtk+

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    7

    Gtk+

    i am developing a calculator in C using GTK+, the code below activates when the cosine button is clicked. i can read the text from the textview, but don't know how to assign the data in text to a char array. i would be grateful for any assistance.


    Code:
    static gchar str[] = "";
    static num1;
    on_BTN_COS_clicked(GtkButton       *button,
                                            gpointer         user_data)
    {
    
    	GtkWidget *resultfld;
    	gchar *text;
    	resultfld = GTK_ENTRY(lookup_widge(button, "entry1"));
    
    	text = gtk_entry_get_text(resultfld); 
    
    ???????	str == text; /// need to asign data in *text to str[] ?????
    
    	
            num1 = strtod( str, &p);
    	num1 = cos(num1);
    	sprintf(str,"%f",num1);
    
    	gtk_entry_set_text(resultfld, str);
    }

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    make sure you have enough memory allocated and use memcpy()

  3. #3
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    use g_strcpy () for copying characters from array to other
    instead of using strtod use g_strtod () or g_ascii_strtod()
    replace sprintf to g_sprintf () and ...
    check glib manual, it tells you more information about these.
    -- Add Your Signature Here --

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW32 and gtk setup in Windows
    By Joelito in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-05-2009, 11:39 AM
  2. Replies: 1
    Last Post: 09-22-2008, 04:49 AM
  3. GTK troubles...again...
    By cornholio in forum Linux Programming
    Replies: 4
    Last Post: 01-16-2006, 01:37 AM
  4. Replies: 1
    Last Post: 10-24-2005, 06:35 AM
  5. QT or GTK
    By mart_man00 in forum Linux Programming
    Replies: 4
    Last Post: 03-24-2003, 10:42 PM