Iam3R 24 Junior Poster

Hello Gurus,

I understood that pragma pack will avoid unneccessary packing.

#pragma pack(2)
provides the allignment on 2 byte buondary.

#pragma pack(2)
provides the allignment on 2 byte buondary.


but the question what i asked was :

will the first member always gets the location that is divisible by four.

i am sorry if i could not understand the info provided correctly.

Iam3R 24 Junior Poster

Not really sure what you want...is it something like this

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

#define ARR_SIZE 10

int main(int argc, char**argv)
{
	int jump = 0, i = 0;
	int *intptr = (int*)NULL;
	int *origptr = intptr;

	intptr = (int*)malloc(ARR_SIZE * sizeof(int));

	for (i = 0; i < ARR_SIZE; ++i)
	{
		intptr[i] = i + 1;
	}

	fprintf(stdout, "enter jump value 0 - %d-> ", (ARR_SIZE - 1));
	fscanf(stdin, "%d", &jump);

	intptr += jump;

	fprintf(stdout, "ans->%d\n", *intptr);

	free(origptr);
	origptr = (int*)NULL;
	intptr = (int*)NULL;
	exit(EXIT_SUCCESS);
}

just like this, but i want it in two dimentional space.

i require a pointer to array of elements ( the number of elements the pointer should be incremented is not known at compile time).

int (*p)[5];
increments by 5 locations
int (*p)[6];
increments by 6 locations

slly i want a pointer to an array but how many elements it should be incremented will be decided at runtime.

dono we have any applications which demands that.

i am just curious.

Thanks.

Iam3R 24 Junior Poster

Hi,
I used Enum constant as a case of swict statement and trying to select by using the pointer to the structure , which internally has a union and a enum member.
the union member again internally have three structures.

even i debugged the code.

the value of the variable s -> st is getting the correct value in debug mode but the function is returning -1.

Please have a look into the code in the attachment.

Thanks,
Danian.

Iam3R 24 Junior Poster

Just curious, If you run this program what's your outcome

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

#define ARR_SIZE 10

int main()
{
	int i = 0;
	unsigned long *myint = NULL;
	myint = (unsigned long*)malloc(ARR_SIZE * sizeof(unsigned long));
	

	for (i = 0; i < ARR_SIZE; ++i)
	{
		fprintf(stdout, "addr->%p\n", (void*)myint++);

	}
	exit(EXIT_SUCCESS);
}

I got

addr->0x8c7010
addr->0x8c7018
addr->0x8c7020
addr->0x8c7028
addr->0x8c7030
addr->0x8c7038
addr->0x8c7040
addr->0x8c7048
addr->0x8c7050
addr->0x8c7058

on a 64 bit Linux box which makes sense since its an array and the addresses have to be consistent.

Then try this one

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

#define ARR_SIZE 10

int main()
{
	int i = 0;
	unsigned long *myint[ARR_SIZE];

	for (i = 0; i < ARR_SIZE; ++i)
	{
		myint[i] = (unsigned long*)malloc(ARR_SIZE * sizeof(unsigned long));
		fprintf(stdout, "addr->%p\n", (void*)myint[i]);
	}
	
	
	exit(EXIT_SUCCESS);
}

My output was

addr->0xfe4010
addr->0xfe4070
addr->0xfe40d0
addr->0xfe4130
addr->0xfe4190
addr->0xfe41f0
addr->0xfe4250
addr->0xfe42b0
addr->0xfe4310
addr->0xfe4370

Why the bigger range? It really depends on how the memory manager doles out memory. In the first example it was required that the memory lie within the requirements of a unsigned long array so the memory manager had allocated it that way...the second example isn't so constricted because its an array of unsigned long pointers....

i agree with that.

can you please suggest me on how my second problem is solved.

if i need a pointer to an array that increments the no of locations that is known at run time, how …

Iam3R 24 Junior Poster

Hi,
I have little idea of padding.

i read in one of the links that :

all character variables gets stored in the memory location that is divided by 1.

all short variables gets stored in the memory location that is divided by 2.

all int variables gets stored in the memory location that is divided by 4.

so

struct one {
          char ch;
    }O;
  
  printf("%d", sizeof(O));

is 1 byte ( no padding here )

struct two {
          short s;
    }T;
  
  printf("%d", sizeof(T));

is 2byte ( no padding here also )

slly for only one integer 4 bytes.

now

struct Test {
            char ch;
             int i;
    }Te;

printf("sizeof(Te)= %d\n",sizeof(Te));

here i will get out put as 8.

the reason is after storing the character variable next three bytes will be padded and after the i will be stored.

even if we write int i; first and char ch; second

the padding will be after the ch because when we create array of structures it will be fast to access.

my doubt is :

when the memory is allocted for char it can store any where regardless of memoey location because any number can be divided by 1.

say if char stores at location 2000.
next three bytes( 2001, 2002,2003 are padded ) and int will be stored at 2004.
but if char gets location 2001 or 2002 or 2003 then the …

Iam3R 24 Junior Poster
/*dynamically allocating memory in called funcion and freeing in caller*/

char**  memall(int ns);

#define Max 20
#include<stdio.h>

int main()
{
        char **s;
        int i,ns;
        printf("no of string you want to store");
        scanf("%d",&ns);
        s=memall(ns);
        for(i=0;i<ns;i++)
        printf("addrs =%u and string=%s\n",(s+i),s[i]);
        for(i=0;i<ns;i++)
        free(s[i]);
        free(s);
       /* s=NULL;
        for(i=0;i<ns;i++)
        printf("%s\n",s[i]);
        *///dont try to access after freeing.
}

char**  memall(int ns)
        {
                char **p;
                char temp[100];
                int i, j;
                int c;
                p=(char **)malloc(ns*sizeof(char *));
                for(i=0;i<ns;i++)
                        printf("%u\n",p+i);
                for(i=0;i<ns;i++)
                {
                        j=0;
                        printf("\nenter the string %d",i+1);
                        while((c=getchar())=='\n'||c==' '||c=='\t');
                        temp[j++]=c;
                        while((c=getchar())!='\n')
                                temp[j++]=c;
                        temp[j] = '\0';
                        p[i]=(char *)malloc(strlen(temp) + 1);
                        printf("%u\n",p[i]);
                        strcpy(p[i],temp);
                }
                return p;
        }

OUT PUT:

[Shark@localhost Dyns]$ gcc daarrof_chrptrs_nl.c
[Shark@localhost Dyns]$ ./a.out
no of string you want to store6
155586568
155586572
155586576
155586580
155586584
155586588

enter the string 1Tom Gunn
155586600
enter the string 2Aia
155586616
enter the string 3Narue
155586632
enter the string 4Ancient Dragon
155586648
enter the string 5Yellow Snow
155586672
enter the string 6C surfer
155586688

addrs =155586568 and string=Tom Gunn
addrs =155586572 and string=Aia
addrs =155586576 and string=Narue
addrs =155586580 and string=Ancient Dragon
addrs =155586584 and string=Yellow Snow
addrs =155586588 and string=C surfer

if we observe the out put the malloc in the loop at line 44 its allocating the memory with a 16 byte difference in its previous allocation and next allocation.

is there any reason underlying for so.

my secong question is

if …

Iam3R 24 Junior Poster

Hi,

I guess answering your question requires some knowledge of how memory is allocated for constants and variables. Now let me answer your question one by one .

1.

char *ptr = "String";
char arr[]= "Array";
*str ='T'; // behaviour is undefined

Now this surely is not allowed for the simple reason that you can't modify pointers who are pointing to string literals and it is this because string literals are stored in read only part of the memory and any attempt to modify them will result in segmentation fault. And since str is a pointer pointing to a string literal(which i have assumed as you haven't mentioned) and therefore modifying it is not allowed.

2.

arr = ptr; // not allowed

This is not allowed because arrays are not pointers. Arrays are automatically allocated space, but can't be relocated or resized where as pointers must be explicitly assigned to point to allocated space (using malloc), but can be reassigned (i.e. pointed at different objects).

3.

int modify(char *p)
{
*p = 'X';// no problem
}

The reason that this segment is executing without any problem is because what you are passing in (pointer)p is the address of an array(arr[]). And since arrays are allocated memory on the stack and therefore the contents of this memory can be modified using pointers. In fact, you can modify any array using pointers and this is what pointers are best at doing.

4.

int main()
      {
      printf("Hello" "World"); // HelloWorld
      printf("%s%s","Hello" "World"); // HelloWorld(someGarbage)
      return 0; …
Iam3R 24 Junior Poster

OK. One step at a time.


ptr points to a string literal, which resides in a read-only section of your data. An attempt to modify it results in segfault, GPF or something else depending of the platform (it may even succeed if a memory protection is not implemented)

arr, however, is allocated on a stack and is just initialized from the literal. This memory is perfectly writable.

Arrays are not pointers. The are "same" only as function arguments.


The preprocessor does concatenate strings, that is right.


You pass one parameter (the concatenated string) and ask to print two.

yes you are right.

but still i dont understand the second one.
printf("%s%s","hello""world");
how that is getting concatenated

as it getting garbages because there is no value for second %s.

Iam3R 24 Junior Poster

Hi,

i dont understand the following; PLZ fix me.

when i try to change the character pointed by pointer the behaviour is undefined.

but when i change the same by using pointer as formal parameter of function it will be ok.

why i cant change the base address of array, when i can change the pointer value.

int main()
{
	char *ptr = "String";
	char arr[]= "Array";
	*str ='T'; // behaviour is undefined
	arr = ptr; // not allowed
	modify(arr);
	return 0;
}

int modify(char *p)
{
	*p = 'X';// no problem
}

the second problem is

2.

int main()
{
     printf("Hello" "World"); // HelloWorld
     printf("%s%s","Hello" "World"); // HelloWorld(someGarbage)
     return 0;
}

how first printf printing o/p: HelloWorkld ( why concatenating).
The printf should stop priting whenever it finds first '\0'.
and the second printf printing some garbages after the strings.

Thanks,
Danian.

Iam3R 24 Junior Poster

Hi ,

i want to use hash tables in my project.
i got few codes in that i got some function called hash()

int hash(char *s)
           {
                  int h =0;
                  for (; *s;s++)
                    h = *s + h * 31;
                    return h % 101;
            }

i understand the process of hash tables but i dont understand
how below statements

h = *s + h * 31;
                              return h % 101;

give a value that will not exceed the array size as choosen(101).
is there any relation between those two statements.

i dont seem the need of using all code here.
though if you want i can provide.

Thanks,
Danian

Iam3R 24 Junior Poster

>Now the question is how the Assember was implemented, i mean which language?
Any compiler can be written in a suitable existing language. The first assembler was probably hand compiled as machine code. Then the second assembler could be written in assembly language and compiled using the first assembler.

>how they are written i mean using which language?
Any language suitable for a compiler or interpreter.

>i read, c compiler was wirtten in C itself .
>then how it was compiled.

With an existing compiler. The first C compiler was probably written in assembly, or some other language that predates C (like B). Then the second compiler could be written in C and compiled using the first compiler. Notice a pattern?

i think you the real code God S

Iam3R 24 Junior Poster

>Can someone explain me what does this mean?
>"40[^\"], %*c"

Assuming it's actually "%40[^\"], %*c", it means read a string of up to 40 characters or until a double quote is found (%40[^\"]), then match a comma, any amount of whitespace, and ignore the next non-whitespace character (%*c).

The %[ specifier is a scanset. It's used to search for a collection of characters and either match based on the scanset or match based on its exclusion (a ^ as the first character means that the scanset is an exclusion scanset).

The * modifier is called assignment suppression. It means that whatever is read will not be assigned to a variable in the argument list. The conversion is simply thrown away.

The format string you posted is actually broken in that it won't get past the scanset because the scanset stops on a double quote character without extracting it. The correct format string would be:

"%40[^\"]\", %*c"

Or to be more strictly correct if there are likely to be more characters in the scanset:

"%40[^\"]%*1[\"], %*c"

This is ignoring the case where the field width ends the scanset specifier rather than one of the scanset character matches.

are these hidden any where , because we generally dont come across such usages is there any guide line which shows that.

Iam3R 24 Junior Poster

And another extremely lightweight unit testing framework is CuTest

its really good .
but i dont understand are these the rules that are followed in the industry.

Iam3R 24 Junior Poster

The Programming languages started with the low level language( 1's and zero's , so no conversion is needed.

Assembly language is used mnemonics ( ADD,INC,DEC) so needs conversions as the machine cannot understand it directly.
there comes the Assembler.

Now the question is how the Assember was implemented, i mean which language?

soon compilers came in to picture.
how they are written i mean using which language?

i read, c compiler was wirtten in C itself .

then how it was compiled.

Thanks,
danian.

Iam3R 24 Junior Poster

>but many books have this specifier.
I hate to break it to you, but many books are written by people who know little more about C than you do. The lesson about %lf is that printf is not a mirror image of scanf in terms of format specifiers.

>where can i find the information related to the format specifiers.
A good book will cover them accurately. A good reference will cover them. And of course, you can refer to the standard itself, though it's a bit harder to glean useful information until you learn how to decipher the legalese.

thnaks Narue,

Iam3R 24 Junior Poster

I compiled the program on both Dev C++ and GCC compiler.
it worked without any errors.

but how the compilers are implemented with out following the standards.( ignoring c is not a block structured language).

Iam3R 24 Junior Poster

>printf("%lf\n",d);
There's no such thing as thing as %lf. You've invoked undefined behavior by using a length modifier that doesn't apply to the type specifier.

but many books have this specifier.
where can i find the information related to the format specifiers.

Iam3R 24 Junior Poster

Hi ,

I read that c is not a block structured language.
means it does not allow defining functions inside other functions.

but this code is not generating any error not even warnings, though we nest the functions.

whats the story.

#include<stdio.h>
int main()      {
        int num;
        num = 10;
        int fun(int n)  {
                printf("The local function");
                return 0;
        }
        fun(num);
        printf("Main function");
        return 0;
        }
Iam3R 24 Junior Poster

Hi
i have written a program to check the precision of float and double values.
i read that the precision of float is 6 digits and double is 10.
but it is showing only 6 for both.

do we need to make any arrangement for the system to print the correct precission.

[Shark@localhost Fresh]$ gcc flt_dbl_prec.c
[Shark@localhost Fresh]$ ./a.out
34.345676 
34.345678
[Shark@localhost Fresh]$ cat flt_dbl_prec.c
int  main()
{
        float f = 34.34567832;
        double d= 34.3456783221;
        printf("%f\n",f);
        printf("%lf\n",d);
return 0;
}
Iam3R 24 Junior Poster

inline: Similar to C++'s inline keyword. It gives you the option of telling the compiler that you want inline expansion rather than real function object code. Inline functions are a safer and easier to use alternative to function macros:

static inline swap ( int *a, int *b )
{
  int save = *a;
  *a = *b;
  *b = save;
}

I'd recommend avoiding this feature. Not only are the rules somewhat tricky, the compiler isn't required to honor a hint for inlining. Further, if the compiler does honor the hint, it could be counter-productive and actually hurt performance instead of help it by increasing the memory footprint and causing thrashing.

_Bool: C99's boolean type. Using _Bool directly is only recommended if you're maintaining legacy code that already defines macros for bool, true, or false. Otherwise, those macros are standardized in the <stdbool.h> header. Include that header and you can use bool just like you would in C++.

#include <stdio.h>
#include <stdbool.h>

int main ( void )
{
  bool b = true;

  if ( b )
    printf ( "Yes\n" );
  else
    printf ( "No\n" );

  return 0;
}

restrict: The restrict keyword is an optimization hint. It says that a pointer is not aliased in the current scope, which means the underlying object is not accessed by another pointer. This hint gives the compiler extra leeway in making assumptions about the pointer and can result in better object code. I'd recommend avoiding this feature too. A lot of people have trouble understanding restrict, …

Iam3R 24 Junior Poster

hi ,
i have read that c99 introduced:
inline,_Bool,restrict,_Complex,_Imaginary

i have used _Bool here but do no how to use remaining all
please any one used the above can help me.

int main()
{
    _Bool b;
      b=true;// giving error  true undeclared ,cant i use that way 
                 // with out using enums.
       b =1;
       if ( b )
           printf (" ok\n");
        else
           printf("No\n");
return 0;
}

Thanks,
Danian.

Iam3R 24 Junior Poster
enum fivenums {Z,O,T,TH,F,FI}
int main()
{
char ch;
int num;
do{
scanf("%d",&num);
switch(num)
{
case Z:
printf("ZERO\n");
break;
case O:
printf("ONE\n");
break;
case T:
printf("TWO\n");
break;
case TH:
printf("THREE\n");
break;
case F:
printf("FOUR\n");
break;
case FI:
printf("FIVE\n");
break;

default :
printf("Invalid\n");
break;
}
getchar();// to eat '\n' terminator so that it waits for below 
}
while ((ch =getchar())=='\n');
return 0;
}

in the above program if i input a number between 0 -3 its working fine.
but if the input is any alphabet i am getting a different out put;

for example:
my input is
1
o/p: ONE
2
o/p: TWO
and if its
a O/P is:
TWO
if i give a its giving the previously read input as out put
i.e 2.
and for any other alphabets also its giving the same o/p.
why is it giving the previous one.
when its already read from the buffer.

Iam3R 24 Junior Poster

You can pass the value to another function - and name the variable something else. But you are not gaining anything by doing that.

void refoo(int newname)
{
    printf("variable newname=%d\n", newname);
}

void foo(void)
{
    int oldname=13;
    printf(" variable oldname=%d\n", oldname);
    refoo(oldname);
}

As long the variable is in scope the name does not/ cannot change. oldname has function scope in the example above.

jim mcnamara
i dont understand how that is related to my question, can you eloborate a little please..

Iam3R 24 Junior Poster

Hi ,
this one is with respect to C.
(i)
when we use array an array index always starts from zero .
is it a standard one? or compilers are implemented that way?
if compilers are implented that way they must have followed some standard.
(ii)
the array name cannot be changed is it the standard or compiler dependent.

i have never heard that array index starts from 1 and base address can be changed.

Thanks,
Danian

Iam3R 24 Junior Poster

I hope what he wants he is just " find the middle element when you have given three elements"

Ex: 1,3,6 the middle element is 3 ( this we cant get just by dividing)
5,6,7 the the middle element is 6.

if this is the case :

int find_mid(int n1, int n2, int n3)
{
  int mid;
  if( n1 > n2 )   {
          if( n3 > n2)
                {
                        if( n3 < n1 )
                                mid = n3;
                        else
                                mid = n1;
                }
         else {
                mid = n2;
        }
 }
 else {
        if( n2 > n3 )
         {
                if ( n1 > n3)
                  mid = n1;
                else
                mid = n3;
         }
        else{
                mid = n2;
        }
}
return mid ;
}

the driver:

int main()
{
        printf( "%d  ", find_mid(3,4,7) );
        printf( "%d  ", find_mid(5,2,8) );
        printf( "%d  ", find_mid(2,9,4) );
        printf( "%d  ", find_mid(7,5,9) );
        printf( "%d  ", find_mid(7,4,6) );
        printf( "%d  ", find_mid(1,3,6) );
        printf( "%d  ", find_mid(5,6,7) );
return 0;
}
Iam3R 24 Junior Poster

yeah, the whole matter is that i want to call void function in while loop as following:

while(search(arg1, arg2, &arg3)){
...
}

(search is void function)

and when i execute the program, im getting following mistake:
"controlling expressions must have scalar type"

while(search(arg1, arg2, &arg3)){
...
}

this you cannot do..! to do that your function should return a value
a void function can be used in the loop in the foll: way

while(somecond)
{
search(arg1, arg2, &arg3);
...
}

unless your function returns a value you cannot use that as a condition in loops as you did.
...!!!!!!!

Iam3R 24 Junior Poster

http://www.libsdl.org/cgi/docwiki.cgi/

Thank you so very muchhh manutm..

its really good.

is it like the gstreamer or any way diffrent? which is most popular and has high demand in terms of job opportunities.

Iam3R 24 Junior Poster
#include <stdio.h>

bool findLeaders(int a[],int n)
{
	bool flag = false;
	int intHighest = a[n-1];

	for(int i=(n-2); i >= 0; i--)
		{
		if(a[i] > intHighest)
			{
			flag = true;
			printf("\nleader = %d", a[i]);
			intHighest = a[i];
			}
		}
	return flag; // returns fals if no leaders
}
void main(void)
{
	static int a[] = {5,1,2,7,3,4,6};
	static int b[] = {9,1,2,8,3,4,6,7};

	if(!findLeaders(a, (sizeof(a)/sizeof(int))))
		{
		puts("No Leaders in a");
		}

	if(!findLeaders(b, (sizeof(b)/sizeof(int))))
		{
		puts("No Leaders in b");
		}
}

i heard that bool is supported by gcc compiler ( for a c program)
but when i saved this file in .c extension and executed, it gave me errors as bool is unrecognized identifer.

is there any special header we need to include for that.

Iam3R 24 Junior Poster

http://www.fluendo.com/shop/product/fluendo-mp3-decoder/

when i click on the link its closing all my opened browsers.

whats that ?

if you have some idea of gstreamer plz let me know the correct place where i get that .
i have already given you my sys info.

becuse i have downloaed the gstreamer files, but its not installing.

Iam3R 24 Junior Poster

Hi,

i like to know what are the different systems that have gstreamer built in, or systems which allows gstreamer to be installed.

I also like to know what this below lines specifies:
I found this in my shell of proc/version file
Linux Version 2.6.9-5.Elsm gcc version 3.4.3 20041212 (red hat 3.4.3-9.El4) #1 smp wed jan 5 19:30:39 EST 2005.

can i install gstreamer on my system.

Thanks.

Iam3R 24 Junior Poster

Thanks for the reply.Its clear now.I want to build a small project in c which includes both graphics and pointer concepts using LINUX OS.Could you please let me know how can i proceed on this?

pointers and graphics:
no good idea:
may be you can start learning ncurses and try with them

Iam3R 24 Junior Poster

firstly im a female
not a male.

does not matter here

secondly its not my entire assignment its a part of it

its your problem , we got nothing to do with it

thirdly i want someone to help me understand with it by providing the source code,rest i have to do myself

this way its very hard to get help here

thanks for all the help you provided

its ok , see you again here with some code.

ms.leena

what a good name you have.

Iam3R 24 Junior Poster

Undefined. In practice it will probably print whatever is next in the stack and potentially corrupt the rest of your program by moving the stack pointer in an unexpected way.

so suppose if we rememeber the previous values of the stack can we expect the same values as out put.
( i believe we should not do this way , but any way the system it self is giving same results every time when i run the program)

Iam3R 24 Junior Poster

sorry for that first thread. i was bit hurry then.plz xcuse me for that.

my prob is .
i want to work on gstreamer. but dont know which systems have the support of it.
i am using red hat linux.
can i install gstreamer on redhat.
i just got the above code while searching for gstreamer .compiled the code on my system but got many errors.
please help me its a bit urgent.
thanks all.

#include <gst/gst.h>
#include <stdbool.h>
static GMainLoop *loop; 

static gbooleanbus_call (GstBus *bus,GstMessage *msg, gpointer user_data)
{    
	switch (GST_MESSAGE_TYPE (msg))   
 	{        
	case GST_MESSAGE_EOS:   
         {                
	g_message ("End-of-stream"); 
	g_main_loop_quit (loop); 
        break;       
       }       
 case GST_MESSAGE_ERROR:   
         {               

	 gchar *debug;   
         GError *err;   
         gst_message_parse_error (msg, &err, &debug);  
         g_free (debug);    
         g_error ("%s", err->message);   
         g_error_free (err);  
         g_main_loop_quit (loop);    
         break;   
         }       
 default:        
    break;  
  }     
return true;
} 

voidplay_uri (gchar *uri)
{   
 GstElement *pipeline;   
  loop = g_main_loop_new (NULL, FALSE);  
   pipeline = gst_element_factory_make ("playbin", "player");   
  if (uri)   
 {       
	 g_object_set (G_OBJECT (pipeline), "uri", uri, NULL); 
 }  
 
  {     
   GstBus *bus;    
     bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));  
      gst_bus_add_watch (bus, bus_call, NULL);  
      gst_object_unref (bus);  
  }  
  
 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); 
 g_main_loop_run (loop);  
 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);  
 gst_object_unref (GST_OBJECT (pipeline));
} 
int main (int argc,      char *argv[])
{   
	 gst_init (&argc, &argv);  
  	 play_uri (argv[1]);  
  	 return 0;
}

please some one let me know on which system this can be executed ?
i think its for gstreamer related
i have red hat .
can i install gstreamer on redhat
thanks,

Iam3R 24 Junior Poster
#include <gst/gst.h>
#include <stdbool.h>
static GMainLoop *loop; 

static gbooleanbus_call (GstBus *bus,GstMessage *msg, gpointer user_data)
{    
	switch (GST_MESSAGE_TYPE (msg))   
 	{        
	case GST_MESSAGE_EOS:   
         {                
	g_message ("End-of-stream"); 
	g_main_loop_quit (loop); 
        break;       
       }       
 case GST_MESSAGE_ERROR:   
         {               

	 gchar *debug;   
         GError *err;   
         gst_message_parse_error (msg, &err, &debug);  
         g_free (debug);    
         g_error ("%s", err->message);   
         g_error_free (err);  
         g_main_loop_quit (loop);    
         break;   
         }       
 default:        
    break;  
  }     
return true;
} 

voidplay_uri (gchar *uri)
{   
 GstElement *pipeline;   
  loop = g_main_loop_new (NULL, FALSE);  
   pipeline = gst_element_factory_make ("playbin", "player");   
  if (uri)   
 {       
	 g_object_set (G_OBJECT (pipeline), "uri", uri, NULL); 
 }  
 
  {     
   GstBus *bus;    
     bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));  
      gst_bus_add_watch (bus, bus_call, NULL);  
      gst_object_unref (bus);  
  }  
  
 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); 
 g_main_loop_run (loop);  
 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);  
 gst_object_unref (GST_OBJECT (pipeline));
} 
int main (int argc,      char *argv[])
{   
	 gst_init (&argc, &argv);  
  	 play_uri (argv[1]);  
  	 return 0;
}

please some one let me know on which system this can be executed ?
i think its for gstreamer related
i have red hat .
can i install gstreamer on redhat
thanks,

Iam3R 24 Junior Poster

Because (a+1)-(a+3) and a+1-a+3 are not the same.

http://mathforum.org/library/drmath/view/58772.html

suppose say a = 2000 and
a[0] is 1

i.e *a = 1

then *a + 1 = 2;
and *a + 3 = 4;
so now
*a + 1 - *a + 3 = 2 - 4 = -2

* (unary, dereferencing) has higher precedence than addition or subtraction, so it's like (*a)+1-(*a)+3.

(*a) + 1 = *a + 1
(*a) + 3 = *a + 3

Iam3R 24 Junior Poster

i run the below code and surprised to see the o/p .

take a look and let me know whats happenning there.

#define print(x) printf(#x"=%d\n",x)
int main(){
        int a[10];
        print(a);
        print(*a);
        print(*a+1);
        print(*a+3);
        print(*a+1-*a+3);
        return 0;
}

Out Put:

[Zonnie@telnet CPz]$gcc funny.c
[Zonnie@telnet CPz]$ ./a.out
a=-1073745776
*a=1
*a+1=2
*a+3=4
*a+1-*a+3=4

regardless of whatever stores at a shouldn't it produce -2.

whats the story ?

Iam3R 24 Junior Poster

can somebody explain the behaviour of the statement

printf("%d");

is it any where depends on the statements that present before or after it.

i have some satatements that allocates memory dynamically. its printing one of that value.

is there any proper reason for undefined behaviour.

Iam3R 24 Junior Poster
system("PAUSE"):

Aia,
sorry to tell you, but the error is not because of that.

its because of #include<stdlib.h>

dont know whether devcpp has the support of stdlib or we need to make any extra arrangements for that while running.

the error is :

Cannot create Makefile: "C:Dev-Cpp\Makefile.win
IO error 32.
Iam3R 24 Junior Poster

i support gaiety's answer with a slight alteration

making the sum zero as the last statement in the first for loop, so that every time it will have a new sum.

if thats not correct can someone provide a correct method.

thank you BestJew, for digging old unsolved thread.

Iam3R 24 Junior Poster

i have just written a small program on DEV C++.
i have been using it for couple of months but i never observed this error.

#include<stdio.h>
int main()
{
    printf("Welcome\n");
    system("PAUSE"):
    return 0;
}

could not create makefile
I/o error 32


any idea? what does that mean

Iam3R 24 Junior Poster

which would make p1d the name of an array of 5 pointers to type int.

this one

int *p1d[5];
Iam3R 24 Junior Poster

foa i believe this is not a bubble sort .

and

for(n=1;n<size1;n++)

is worng because

in the process all ready sorted ( in descending order ) elements again go up.

when i =0 n goes from 1-4
n = 1 to 4 all are less than 8 no replacements

when i =1 n goes from 1-4
n =1 no replacement
n=2, i=1; 4<5 : replacement, so list will be 8 5 4 2 3
n= 3,4 no replacement

when i =2 n goes from 1-4
i =2 , n =1 ;4 < 5 : replacement, so list will be 8 4 5 2 3 (wrong)
n =2,3,4 no replacement

when i =3 n goes from 1-4
i = 3, n =1 ; 2 < 4 : replacement , so list will be 8 2 5 4 3
i =3, n = 2 ; 4 < 5 : replacement , so list will be 8 2 4 5 3
n = 3 , 4 no change

when i =4 n goes from 1-4
i = 4, n =1 ; no change
i = 4 ,n = 2; 3<4 ; replacement , so list will be 8 2 3 5 4
i =4, n =3 4 < 5 replacement , so list will be 8 2 3 4 5
i = 4 n =4 no change
so the final out put

Iam3R 24 Junior Poster

Dont know these types of questions are asked here or not but if any one has idea please help me.

i just started started learning system programming and want to pursue a career in the sys prog area.

below is the program that use a fork() call.
i read in one of the tutorials that parent process and child process uses different address spaces and runs concurrently.

that meas each process gets some slice of cpu time, then the statements in that process are executed.

my Questions:

1.is there any way to know how much timeslice each process is getting.

2.what kind of scheduling its using

3. can i print the out put one page at a time ( should wait for keypress to print next page)

4. any links that provides good system programming info(message queues, pipes,shared memory etc.. )

5. appications that uses sockets
below is some example prog:

#include  <stdio.h>
#include  <sys/types.h>

#define   MAX_COUNT  200

void  ChildProcess(pid_t);                /* child process prototype  */
void  ParentProcess(pid_t);               /* parent process prototype */

void  main(void)
{
     pid_t  pid;

     pid = fork();
     if (pid == 0) 
          ChildProcess(pid);
     else 
          ParentProcess(pid);
}

void  ChildProcess(pid_t pid)
{
     int   i;
     char buf[40];
     for(i=1; i <= MAX_COUNT; i++) {
          sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
          write(1, buf, strlen(buf));
     }
}

void  ParentProcess(pid_t pid)
{
     int   i;    
     char buf[40];
     for(i=1; i <= MAX_COUNT; i++) {
          sprintf(buf, "This line is from …
Iam3R 24 Junior Poster

its already available for free on internet.
i dont remember the exact site.
thought you ppl have some idea.

Narue:
If you want the book that badly, go buy it.

Chilton :
I'd suggest buying it.

i already have one .

i want to have one on my computer.
any ways thanks all.

Iam3R 24 Junior Poster

i hope this is what you want ..

i just edited , but some unneccessary statements/ variable are present that will not harm our prgram.

#include<stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 1000
#define SIZE 100
void search_string(char *file, char *pat);

int main()
{
      int counter = 0;
      int i=0;
     char ch;
     const char filename[] = "in.txt";
     char pat[50];
    FILE *file = fopen(filename, "r");
    if ( file != NULL )
    {
     char line [ MAX ];
     while(isspace(ch=fgetc(file))) ;
     pat[i++] = ch;
     while(!(isspace(ch=fgetc(file))))
     pat[i++] = ch;
     pat[i] = '\0';
     rewind(file);
     while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
     {
            ++counter;
            printf( "%d  ", counter);
            fputs ( line, stdout ); /* write the line */
            search_string(line,pat);
   }
      printf( "\n\n");
      //search_string(line);
      fclose ( file );
   }
   else
   {
      perror ( filename );
   }

   char wait;
   scanf( "%c", &wait );
   return(0);
}
void search_string(char *file, char *pat)
{
        char *ptr, *strptr, word[SIZE] = {" "};
        int i = 0, j = 0;
        int spc =0;
           /*
        while (*ptr != '\0')
        {
                if (isspace(*ptr) && spc == 0)
                                 {
                                    spc  = 0;
                                         }
                if(spc != 0 && isspace(*ptr))
                                                break;
                if(isalnum(*ptr))
                                {
                                    spc =1;
                                    word[i] = *ptr ; // file[i];
        / / here file[i] is blank , is a problem do you really want that
                                   i++;
                        }
                    ptr++;
                 }
              word[i]='\0';
             */

        strptr = file;
        while ((strptr = strstr(strptr, pat)) != NULL)
        {
                strptr++;
                j++;
        }
        printf("%s occured %d times in the string\n", pat, j);
}
Grn Xtrm commented: Thanks for the help. +1
Iam3R 24 Junior Poster

But, is there any proposed solution to what I'm looking for?

you can also use function pointers to do same thing.

Iam3R 24 Junior Poster

I got my function to work somewhat but it only prints the number of occurrences of the first word of the last line in the last line only.

because you are calling the function search_string(line); after the statement

while ( fgets ( line, sizeof line, file ) != NULL )
{
        :
        :
}

by the time it comes out of while line is having last line of the file.


I just want to get the program to search all lines for the first word of the txt file.

probably you want to search for the first word(Secret) in all line
you can modify so easily.

i have just edited your code, i dont completly understand your requirement , but this works fine for all the lines.
you can modify as per your Req:

Here is the revised code

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 1000
#define SIZE 100
void search_string(char *file);

int main()
{
    int counter = 0;
    const char filename[] = "in.txt";        
    FILE *file = fopen(filename, "r");    
    if ( file != NULL )
    {
     char line [ MAX ]; 

      while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
      {
            ++counter;
            printf( "%d  ", counter);
            fputs ( line, stdout ); /* write the line */
            search_string(line);   
   }
      printf( "\n\n");
      //search_string(line); 
      fclose ( file );
   }
   else
   {
      perror ( filename ); 
   }
   
   char wait;
   scanf( "%c", &wait );
   return(0);
} …
Iam3R 24 Junior Poster

please provide the free pdf link of k & R c prog lang.

i spent lot of time in googling but couldnot get it.

thanks in adv.

Iam3R 24 Junior Poster

The code is perfect and no errors execpt few things that shuold be avoided.
may be you want to print from

5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
:
:
5 * 10 = 50

here is your code with slight modifications and proper posting:
follow this next time

#include<stdio.h>

int main()
{
        int i, num;
        printf( " Enter any number " );
        scanf( "%d", &num );
        for( i=1 ;i <=10; i++ )
            printf( "  \t %d * %d = %d \n ", num, i, num*i ) ;
        return 0;
}