LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-01-2017, 05:29 PM   #1
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
typedef struct issues


I am updating a open source file it has this within it.
Code:
typedef struct
{
	int r, g, b, a;
}	Color, *PColor;
then it uses this
Code:
Color c;
within the c file, the two where originally declared within the old (other) C file. I split it, put the definition in to the header file, modded the functions that use this, and got everything back to no errors (so far) leaving me with this one .
Code:
> gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c  main.c -o tryme
options.c: In function 'mh_parse_options_array':
options.c:218:5: error: a label can only be part of a statement and a declaration is not a statement
     Color c;
     ^
it actually worked one time, then I added another Color c; in a different case off the switch and then it started giving me all of these problems - that I wittled down to just that last one.

I've seen it shown that it can be written like that but without any further example

ie
Code:
Absolutely valid. Usually, you can take full advantage of this way by defining two types together:

typedef struct
{
 int a;
 int b;
} S1, *S1PTR;
https://stackoverflow.com/questions/...r-to-structure
But it does not explain any further then that. or show how to then use it within a file.

Oh yes.
and this is what is used to call it in to a function
Code:
int parse_color (char *optarg, PColor c, int a)

Last edited by BW-userx; 08-01-2017 at 05:47 PM.
 
Old 08-01-2017, 05:56 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,444
Blog Entries: 4

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
You need us to show the offending source-code in context.
 
Old 08-01-2017, 06:07 PM   #3
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Quote:
Originally Posted by sundialsvcs View Post
You need us to show the offending source-code in context.
yeah Ok -- I was wondering if all of that is needed.

Code:
//#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "mhsetroot.h"
#include "getinfo.h"
#include "options.h"

int getHex (char c)
{
	switch (c)
	{
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			return c - '0';
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
			return c - 'A' + 10;
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
			return c - 'a' + 10;
	default:
return 0;
	}// end switch
} // end function

int parse_color (char *optarg, PColor c, int a)
{
	if (optarg[0] != '#')
		return 1;

	if ((strlen (optarg) != 7) && (strlen (optarg) != 9))
		return 1;

	c->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
	c->g = getHex (optarg[3]) * 16 + getHex (optarg[4]);
	c->b = getHex (optarg[5]) * 16 + getHex (optarg[6]);
	c->a = a;

	if (strlen (optarg) == 9)
		c->a = getHex (optarg[7]) * 16 + getHex (optarg[8]);

	return 0;
}


    char str1[10];
    char str2[10];
    char str3[10];
    char str4[10];
    char *geo;

	int w = 0;
	int  h = 0;


void init_parse_options(int argc, char **argv){

	mh_parse_options_array(argc, argv, 0);

	}

static void mh_parse_options_array(int argc, char **argv, int finalrun){


	static char string_options [] = "fFCT:hvdce:t:g:n:s:a:";
//  no_argument  0
// required_argument 1
// optional_argument 2
static struct option long_options[] = {
 // a b c d e f g h i j k l m n o p q r s t u v w x y z
		{"fullscreen", 0,  0,  'F'},
	    {"fill",  0 ,  0, 'f'},
	    {"center", 0 ,0,'C'},
	    {"tile",1 , 0, 'T'}, // arg n=normal v = vertical
	    {"flip-image-horz", 0 ,0, 'h'},
	    {"flip-image-vert", 0 , 0 , 'v'},
	    {"flip-image-dia", 0, 0, 'd'},
	    {"resize-center", 0, 0, 'c'},
	    {"resize-flip",1 , 0, 'e'},
	    {"resize-tile", 1, 0, 't'}, // no arg for normal tile
	   {"geometry", 1, 0, 'g'},
	    {"filename", 1, 0, 'n'},
	    {"gradient", 1, 0, 'a'},
	    // add colors
	    {"solid", 1 , 0 , 's'},

	      {"add", 1,0, 200},
	      {"addd", 1, 0 , 201},
		{0,0,0,0}
	}; // end options

	int c;
	int optind = 0;
	int option_index = 0;

	while (( c = getopt_long_only(argc, argv, string_options, long_options,&option_index) ) != -1) {
		printf("C is %d\n",c);
		switch (c) {
			case 'F':
			    mode = FULLSCREEN;
				printf("optind %d orptarg  %s  mode %d \n", optind, optarg,  (int) mode);
				break;
			case 'f':
				mode = FILL;
				printf("orptarg  %s   mode %d \n", optarg, (int) mode);
				break;
			case 'C':
				mode = CENTER;
				printf("optind %d orptarg  %s  mode %d \n", optind, optarg,  (int) mode);
				break;
			case 'T':
				if (strcmp(optarg, "v")== 0)
				{
					mode = TILEV;
					printf("v: orptarg  %s  tilev mode %d  argv[argc-1] %s\n", optarg, (int) mode, argv[2]);
				}
				else if (strcmp(optarg,  "h") == 0)
				{
					mode = TILEH;
					printf("v: orptarg  %s   tileh mode %d  argv[argc-1] %s\n", optarg, (int) mode, argv[2]);
				}
				else if (strcmp(optarg, "hv") == 0 )
				{
					mode = TILEHV;
					printf("v: orptarg  %s   tilehv mode %d  argv[argc-1] %s\n", optarg, (int) mode, argv[2]);
				}
				else if(strcmp(optarg, "n") == 0)
				{
					mode = TILE;
					printf("tile - set - optarg %s optind %d\n",optarg, optind);
				}
				break;
			case 'h':
				mode = FLIPIMGH;
				break;
			case 'v':
				mode = FLIPIMGV;
				break;
			case 'd':
				mode = FLIPIMGD;
				break;
			case 'c':
				mode = DCENTER;
				break;
			case 'e':
				if (strcmp(optarg, "v") == 0)
				{
					mode = DFLIPIMGV;
				}
				else if(strcmp(optarg, "d") == 0 )
				{
					mode =DFLIPIMGD;
				}
				else if(strcmp(optarg, "h") == 0 )
				{
					mode = DFLIPIMGH;
				}
				break;
			case 't': // resize tile
				if (strcmp(optarg, "v")== 0)
				{
					mode = DTILEV;
				}
				else if (strcmp(optarg,  "h") == 0)
				{
					mode = DTILEH;
				}
				else if (strcmp(optarg, "hv") == 0 )
				{
					mode = DTILEHV;
				}
				else if(strcmp(optarg, "n") == 0 )
				{
					mode = DTILE;
				}
				break;
			case 'g':
				strcpy (str1, optarg);
				if (findX(str1, &w, &h) == 0 )
				{
					newW = w;
					newH = h;
					printf("\n\nmode %d : width %d height %d\n\n", (int)mode, newW,newH);
				}
				break;
			case 'n':
				printf("in case file %s\n", optarg);
				filename = optarg;
				break;
			case 's':
				printf("In solid color\n");
				/**
		//		Color c;
				parse_color (optarg, &c, 255); // alpha = 255
				imlib_context_set_color (c.r, c.g, c.b, c.a);
				imlib_add_color_to_color_range (1);
			***/
				break;
			case 'a':
																				// screenW - screenH
				imlib_image_fill_color_range_rectangle (0, 0, 1600, 800, atoi(optarg)); // optarg = int
				break;

			case 200:
				//needs to add better meand to look ahead for -add "#FFFFFF" -add "#FFFFFF"
				printf("add\n");
				/**
			    Color *c;
				parse_color (optarg, &c, 255); // alpha = 255
				imlib_context_set_color (c.r, c.g, c.b, c.a);
				imlib_add_color_to_color_range (1);
				***/
				break;
		case 201:
				//needs to add better meand to look ahead for -add "#FFFFFF" -add "#FFFFFF"
				printf("addd color\n");
				printf("optind %d argc %d\n", optind, argc);
				/**
			    Color *c;
				parse_color (optarg, &c, 255); // alpha = 255
				imlib_context_set_color (c.r, c.g, c.b, c.a);
				imlib_add_color_to_color_range (1);
				***/
				break;


			 case '?':
                printf("Unknown option\n");
                break;


		default:
			break;

		} // end switch
	} // end while

	  if (optind < argc)
        {
          printf ("\n\n\nnon-option ARGV-elements: ");
          while (optind < argc)
          printf ("%s ", argv[optind++]);
          printf ("\n\n\n");
        }

} //end function
header
Code:
#ifndef OPTIONS_H
#define OPTIONS_H

typedef struct
{
	int r, g, b, a;
}	Color, *PColor;

char mode;
char *colors;
char *filename;
int newW;
int newH;
int parse_color (char *optarg, PColor c, int a);
int getHex (char c);
void init_parse_options(int optarg, char **argv);
static void mh_parse_options_array(int argc, char **argv, int finalrun);

#endif
Code:
case 200:
// -add "#FFFFFF" 
printf("add\n");

// optarg = "#FFFFFF"

Color *c;
parse_color (optarg, &c, 255); // alpha = 255
imlib_context_set_color (c.r, c.g, c.b, c.a);
imlib_add_color_to_color_range (1);

break;
with parse_color uncommended it gets this -- (without saying) due to Color c;
Code:
gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c  main.c -o tryme
options.c: In function 'mh_parse_options_array':
options.c:231:26: warning: passing argument 2 of 'parse_color' from incompatible pointer type [-Wincompatible-pointer-types]
     parse_color (optarg, &c, 255); // alpha = 255
                          ^
options.c:48:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
 int parse_color (char *optarg, PColor c, int a)
     ^
options.c:232:31: error: request for member 'r' in something not a structure or union
     imlib_context_set_color (c.r, c.g, c.b, c.a);
                               ^
options.c:232:36: error: request for member 'g' in something not a structure or union
     imlib_context_set_color (c.r, c.g, c.b, c.a);
                                    ^
options.c:232:41: error: request for member 'b' in something not a structure or union
     imlib_context_set_color (c.r, c.g, c.b, c.a);
                                         ^
options.c:232:46: error: request for member 'a' in something not a structure or union
     imlib_context_set_color (c.r, c.g, c.b, c.a);
                                              ^

Last edited by BW-userx; 08-01-2017 at 06:25 PM.
 
Old 08-01-2017, 06:42 PM   #4
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
I moved the typedef strct into C commened out both
Code:
//int parse_color (char *optarg, PColor c, int a);
//int getHex (char c);

Code:
options.c:54:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
had Color *c; removed the pointer to it, then I only had one Color c;

having it like this compies without error
Code:
case 's':
printf("In solid color\n");

Color c;
parse_color (optarg, &c, 255); // alpha = 255
imlib_context_set_color (c.r, c.g, c.b, c.a);
imlib_image_fill_rectangle (0, 0, 1600, 800);

break;

case 'a':
                                    // screenW - screenH
imlib_image_fill_color_range_rectangle (0, 0, 1600, 800, atoi(optarg)); // optarg = int
break;

case 200:
// -add "#FFFFFF" -add "#FFFFFF"
printf("add\n");
/**
//	    Color c;
parse_color (optarg, &c, 255); // alpha = 255
imlib_context_set_color (c.r, c.g, c.b, c.a);
imlib_add_color_to_color_range (1);
***/

break;

case 201:
// -addd "#FFFFFF" -addd "#FFFFFF"
printf("addd color\n");
printf("optind %d argc %d\n", optind, argc);
/**
Color c;
parse_color (optarg, &c, 255); // alpha = 255
imlib_context_set_color (c.r, c.g, c.b, c.a);
imlib_add_color_to_color_range (1);
**/
break;
I get one to work but as soon as I un comment the other ones I get errors again as noted.

Code:
> gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c  main.c -o tryme
options.c: In function 'mh_parse_options_array':
options.c:236:15: error: redeclaration of 'c' with no linkage
         Color c;
               ^
options.c:221:12: note: previous declaration of 'c' was here
      Color c;
            ^
options.c:247:14: error: redeclaration of 'c' with no linkage
        Color c;
              ^
options.c:236:15: note: previous declaration of 'c' was here
         Color c;
               ^

Last edited by BW-userx; 08-01-2017 at 07:07 PM.
 
Old 08-01-2017, 06:57 PM   #5
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 663

Rep: Reputation: 252Reputation: 252Reputation: 252
gcc error messages can be terse but the warning and errors in post #3 are pretty clear:
Code:
options.c:231:26: warning: passing argument 2 of 'parse_color' from incompatible pointer type [-Wincompatible-pointer-types]
     parse_color (optarg, &c, 255); // alpha = 255
options.c:48:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
 int parse_color (char *optarg, PColor c, int a)
Think about how you are passing Color ** instead of a Color *.


For post #4 try putting each case with a Color c declaration in its own scope:
Code:
			case 200:
				// -add "#FFFFFF" -add "#FFFFFF"
				printf("add\n");
                                {
                         	    Color c;
			            parse_color (optarg, &c, 255); // alpha = 255
				    imlib_context_set_color (c.r, c.g, c.b, c.a);
				    imlib_add_color_to_color_range (1);
                                }
				break;
HTH
 
Old 08-01-2017, 06:57 PM   #6
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
OK UP DATE

I got it to work but it is only letting me declare it once. see post #4 above
 
Old 08-01-2017, 07:00 PM   #7
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Quote:
Originally Posted by norobro View Post
gcc error messages can be terse but the warning and errors in post #3 are pretty clear:
Code:
options.c:231:26: warning: passing argument 2 of 'parse_color' from incompatible pointer type [-Wincompatible-pointer-types]
     parse_color (optarg, &c, 255); // alpha = 255
options.c:48:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
 int parse_color (char *optarg, PColor c, int a)
Think about how you are passing Color ** instead of a Color *.


For post #4 try putting each case with a Color c declaration in its own scope:
Code:
			case 200:
				// -add "#FFFFFF" -add "#FFFFFF"
				printf("add\n");
                                {
                         	    Color c;
			            parse_color (optarg, &c, 255); // alpha = 255
				    imlib_context_set_color (c.r, c.g, c.b, c.a);
				    imlib_add_color_to_color_range (1);
                                }
				break;
HTH
yeh I caught that after I posted, I had one Color *c; when it needed to me Color c; and typedef in the right file.

its from hit and miss moving everything around and trying different tactics - hacking

I got it working like it should but it is only letting me declare it once, or in one case but not any other ones.

see post #4

Last edited by BW-userx; 08-01-2017 at 07:03 PM.
 
Old 08-01-2017, 07:15 PM   #8
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Looks Like I had to declared it just inside of while loop just before the switch and rename it,
Code:
	Color co;
and change it to that, then change everything that referenced c.x to co.x now it is working. par for course.

Last edited by BW-userx; 08-01-2017 at 07:54 PM.
 
Old 08-02-2017, 07:54 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,444
Blog Entries: 4

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
A typedef merely describes what a Color looks like. You should declare the type only once, e.g. in a header file, before any uses of the type-name are made.

The author's type declarations mean that Color *foo; and PColor foo; are equivalent, because s/he declared that PColor is "pointer to Color."

In C, you cannot declare a variable twice. Some languages have "block scope" for local variables but C does not. It has global variables and local variables. At the start of the function, declare all local variables that will exist in that function. They will be available throughout the function, and, if the function calls itself recursively, will be distinct for each recursive instance.

Last edited by sundialsvcs; 08-02-2017 at 07:57 AM.
 
Old 08-02-2017, 08:17 AM   #10
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Quote:
Originally Posted by sundialsvcs View Post
A typedef merely describes what a Color looks like. You should declare the type only once, e.g. in a header file, before any uses of the type-name are made.

The author's type declarations mean that Color *foo; and PColor foo; are equivalent, because s/he declared that PColor is "pointer to Color."

In C, you cannot declare a variable twice. Some languages have "block scope" for local variables but C does not. It has global variables and local variables. At the start of the function, declare all local variables that will exist in that function. They will be available throughout the function, and, if the function calls itself recursively, will be distinct for each recursive instance.
I cannot speak for the one that wrote that originally, though it was/is a C program that it is in. that being said. I have no idea why they did it that way, it worked so I wasn't going to mess with it. But it looks like its time to.
Thanks
 
Old 08-02-2017, 08:57 AM   #11
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Quote:
Originally Posted by sundialsvcs View Post
A typedef merely describes what a Color looks like. You should declare the type only once, e.g. in a header file, before any uses of the type-name are made.

The author's type declarations mean that Color *foo; and PColor foo; are equivalent, because s/he declared that PColor is "pointer to Color."

In C, you cannot declare a variable twice. Some languages have "block scope" for local variables but C does not. It has global variables and local variables. At the start of the function, declare all local variables that will exist in that function. They will be available throughout the function, and, if the function calls itself recursively, will be distinct for each recursive instance.
but looking at this page which is not a typedef strut but just a plane ole stuct

it states
Code:
#include <stdio.h>
#include <string.h>
 
struct Books {
   char  title[50];
   char  author[50];
   char  subject[100];
   int   book_id;
};
 
int main( ) {

   struct Books Book1;        /* Declare Book1 of type Book */
   struct Books Book2;        /* Declare Book2 of type Book */
would that not be the same as,

Code:
typedef struct {
int a,b,c,d;
} <tag/name>Color, *PColor; < declared *PColor pointer to type Color.
// side stepping.
Code:
typedef struct Color {
int a,b,c,d;
};


int main()

struct Color *PColor; <-- declared *PColor pointer to type Color.
But errors errors errors is what I get,



Code:
 gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c  main.c -o tryme
options.c:17:1: warning: useless storage class specifier in empty declaration
 }; // *PColor;
 ^
options.c: In function 'mh_parse_options_array':
options.c:250:27: error: 'cl' undeclared (first use in this function)
     parse_color (optarg, &cl, 255); // alpha = 255
                           ^
options.c:250:27: note: each undeclared identifier is reported only once for each function it appears in
Code:
typedef struct Color
{
	int r, g, b, a;
}; //	*PColor;

typedef struct Color *PColor;
gets me this
Code:
options.c:17:1: warning: useless storage class specifier in empty declaration
 }; // *PColor;
 ^
options.c: In function 'mh_parse_options_array':
options.c:250:27: error: 'cl' undeclared (first use in this function)
     parse_color (optarg, &cl, 255); // alpha = 255
                           ^
changing it to this
Code:
typedef struct 
{
	int r, g, b, a;
}Color; //	*PColor;

typedef struct Color *PColor;
gets me this:
Code:
ptions.c: In function 'parse_color':
options.c:89:4: error: dereferencing pointer to incomplete type 'struct Color'
  cl->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
    ^
options.c: In function 'mh_parse_options_array':
options.c:250:27: error: 'cl' undeclared (first use in this function)
     parse_color (optarg, &cl, 255); // alpha = 255
                           ^
options.c:250:27: note: each undeclared identifier is reported only once for each function it appears in
BUT when I put it back just like it was beforehand
Code:
typedef struct
{
	int r, g, b, a;
}	Color, *PColor;
I get no errors whatsoever and it works
Code:
userx%slackwhere ~ options-pratice > gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c  main.c -o tryme
userx%slackwhere ~ options-pratice >
good compile no errors.


-- sets the color whatever one picks via hex "#fab123" boom got color on desktop background.
Code:
userx%slackwhere ~ options-pratice > ./tryme -s  "#a4f442"
C is 115
In solid color
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex



non-option ARGV-elements: ./tryme -s #a4f442
for two colors
Code:
userx%slackwhere âš¡ options-pratice âš¡> 
userx%slackwhere âš¡ options-pratice âš¡> ./tryme --add  "#a4f442" -add "#a45542" --gradient 45
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 97



non-option ARGV-elements: ./tryme --add #a4f442 -add #a45542 --gradient 45 


in main after parse options  0
in setImage loadimage.c
in setrootatoms
and one more just to show off a little
Code:
> ./tryme --resize-center -g 400x600 --add "#a4f442" --add "#a45542" --gradient 45  --filename /home/userx/slackware_14.jpg
C is 99
C is 103
in  findX


mode 11 : width 400 height 600

C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 97
C is 110
in case file /home/userx/slackware_14.jpg



non-option ARGV-elements: ./tryme --resize-center -g 400x600 --add #a4f442 --add #a45542 --gradient 45 --filename /home/userx/slackware_14.jpg 


in main after parse options  11
in setAlpha
in setImage loadimage.c
in setrootatoms
resized image to whatever I tell it to be with two colors and a gradient -
it works just like it is suppose to.

SOOOOOOo now what ya say about that? Because I have no cue.

Last edited by BW-userx; 08-02-2017 at 11:13 AM.
 
Old 08-02-2017, 09:37 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,235

Rep: Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979
There is a stray '1' in it
Code:
typedef struct Color {
    int 1a,b,c,d;
};

struct Color *PColor; <-- declared *PColor pointer to type Color.
 
Old 08-02-2017, 10:21 AM   #13
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Quote:
Originally Posted by NevemTeve View Post
There is a stray '1' in it
Code:
typedef struct Color {
    int 1a,b,c,d;
};

struct Color *PColor; <-- declared *PColor pointer to type Color.
that is just pseudo code to example only not working code. sorry for the confusion.
fat finger typing is to blame

besides that would not mess anything up anyways I'd just be referenced as 1a

Last edited by BW-userx; 08-02-2017 at 11:13 AM.
 
Old 08-02-2017, 11:39 PM   #14
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 663

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by sundialsvcs View Post
... Some languages have "block scope" for local variables but C does not. ...
Au contraire, mon frère.
http://en.cppreference.com/w/c/langu...pe#block_scope

An example of what I attempted to explain in post #5:
Code:
#include <stdio.h>

typedef struct Color
{
    int r, g, b, a;
} Color;

int main(int argc, char *argv[]) {
    Color c = {255, 0, 0, 0};
    switch(argc) {
        case 0:
        {
            Color c = {0, 255, 0, 0};
            break;
        }
        case 1:
        {
            Color c = {127, 0, 255, 64};
            printf("case 1 c.r= %d\n", c.r);
            break;
        }
        default:
            break;
    }
    printf("c.r= %d\n", c.r);
}
output:
case 1 - c.r= 127
c.r= 255
 
1 members found this post helpful.
Old 08-03-2017, 07:39 AM   #15
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,670

Original Poster
Rep: Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864Reputation: 864
Quote:
Originally Posted by norobro View Post
Au contraire, mon frère.
http://en.cppreference.com/w/c/langu...pe#block_scope

An example of what I attempted to explain in post #5:
Code:
#include <stdio.h>

typedef struct Color
{
    int r, g, b, a;
} Color;

int main(int argc, char *argv[]) {
    Color c = {255, 0, 0, 0};
    switch(argc) {
        case 0:
        {
            Color c = {0, 255, 0, 0};
            break;
        }
        case 1:
        {
            Color c = {127, 0, 255, 64};
            printf("case 1 c.r= %d\n", c.r);
            break;
        }
        default:
            break;
    }
    printf("c.r= %d\n", c.r);
}
output:
case 1 - c.r= 127
c.r= 255
Am I doubting? I know hat I see, is nothing but errors when I try it like that, and every other combination I seen in what google had out there and but everything way I tried failed.

It too may be because of the way he wrote the means to gain (retrieve) the information. they way you are showing I've tried and it failed and still does.

the setup
Code:
typedef struct Color
{
	int r, g, b, a;
}	Color; //, *PColor;
the functions that uses it:
Code:
int getHex (char c)
{
	//printf("in gethex\n");
	switch (c)
	{
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			return c - '0';
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
			return c - 'A' + 10;
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
			return c - 'a' + 10;
	default:
return 0;
	}// end switch
} // end function


int parse_color (char *optarg, Color co, int a)
{
	if (optarg[0] != '#')
		return 1;

	if ((strlen (optarg) != 7) && (strlen (optarg) != 9))
		return 1;

/**pointers **/	co->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
	co->g = getHex (optarg[3]) * 16 + getHex (optarg[4]);
	co->b = getHex (optarg[5]) * 16 + getHex (optarg[6]);
	co->a = a;

	if (strlen (optarg) == 9)
		co->a = getHex (optarg[7]) * 16 + getHex (optarg[8]);

	return 0;
}
The fails / Errors by declaring it like you say it needs to be.
Code:
options.c:67:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
  co->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
    ^
options.c:68:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
  co->g = getHex (optarg[3]) * 16 + getHex (optarg[4]);
    ^
options.c:69:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
  co->b = getHex (optarg[5]) * 16 + getHex (optarg[6]);
    ^
options.c:70:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
  co->a = a;
    ^
options.c:73:5: error: invalid type argument of '->' (have 'Color {aka struct Color}')
   co->a = getHex (optarg[7]) * 16 + getHex (optarg[8]);
     ^
options.c: In function 'mh_parse_options_array':
options.c:217:26: error: incompatible type for argument 2 of 'parse_color'
     parse_color (optarg, &co, 255); // alpha = 255
                          ^
options.c:59:5: note: expected 'Color {aka struct Color}' but argument is of type 'Color * {aka struct Color *}'
 int parse_color (char *optarg, Color co, int a)
     ^
options.c:232:30: error: incompatible type for argument 2 of 'parse_color'
     if (parse_color (optarg, &co, 255) == 1 ) // alpha = 255
                              ^
options.c:59:5: note: expected 'Color {aka struct Color}' but argument is of type 'Color * {aka struct Color *}'
 int parse_color (char *optarg, Color co, int a)
     ^
options.c:257:26: error: incompatible type for argument 2 of 'parse_color'
     parse_color (optarg, &co, 255); // alpha = 255
                          ^
options.c:59:5: note: expected 'Color {aka struct Color}' but argument is of type 'Color * {aka struct Color *}'
 int parse_color (char *optarg, Color co, int a)
It has to be due to him using pointers in the parse_color function.

or is it?

Leur est plus qu'une façon de peauter un chat

But definitely thanks for that web link on (data) Scope - I'm now going into my first attempt for a link list. to put filenames with their paths to them in it.

steps:
get path to dir, check dir to be sure it is a dir , open dir, search for files (leave out . and .. then insert path/filename into linked list. close dir.

create function to cycle through list and send information to imlib for processing.

just one, and one after the other, and on a random cycle with a user set time to change image options.

free list when done.

sounds easy but I know I'm going to have errors - that is my (modus operandi) MO

Last edited by BW-userx; 08-03-2017 at 08:01 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Having issues with typedef struct in c andy89038 Programming 2 07-09-2010 10:52 AM
[SOLVED] Question about Kernel pid_namespace - struct pid and struct upid sreeharsha.t Linux - Kernel 4 03-19-2010 04:41 AM
GCC compile problem:struct A have a member variable which is just a struct type name? leon.zcom Programming 3 04-18-2008 04:40 PM
C declaration problem for a "typedef struct". Spirals Linux - Software 3 03-17-2008 07:52 AM
typedef a union as a struct? KasperLotus Programming 3 03-09-2007 01:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration