gerard4143 371 Nearly a Posting Maven

Here's a list of errors/warnings you should address before we look at the linked list

testit.c: In function ‘statistics’:
testit.c:33: error: ‘name’ undeclared (first use in this function)
testit.c:33: error: (Each undeclared identifier is reported only once
testit.c:33: error: for each function it appears in.)
testit.c:35: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘char (*)[255]’
testit.c:46: error: ‘plik’ undeclared (first use in this function)
testit.c:46: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘char (*)[255]’
testit.c:54: warning: implicit declaration of function ‘strcasecmp’
testit.c:85: error: ‘prevoius’ undeclared (first use in this function)

gerard4143 371 Nearly a Posting Maven

Probably a typo:


while((a=fscanf(plik, "%s", &quest))!= EOF)

What's plik?

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

Thanks for the reply,

But I still have one question: how can you explain the fact that you can fill the array this way?:

struct my_struct my_array[] = {
    { TYPEA },
    { TYPEB }
  };

without nothing for the data field?

And the one reason I needed pointers to structures, is to be able to call them to get a size, and not fill them immediately. Do you think that can be done with this method?

If that's a problem then try:

struct my_struct my_array[] = {
    { TYPEA, NULL },
    { TYPEB, NULL }
  };
gerard4143 371 Nearly a Posting Maven

Number - 2
the main function returns the address of main as its exit value..

gerard4143 371 Nearly a Posting Maven

Try something like below:

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

/*our dummy data set*/

#define DATASIZE 100
#define DATSET "ThiS iS ThE mESSaGE 23h to sENd ov4er th4re\n"

int main(int argc, char**argv)
{
	int i = 0;
	char ch[DATASIZE];
	char *pstr = NULL;

	strncpy(ch, DATSET, DATASIZE);
	
	for (i = 0; i < strlen(ch); ++i)
		ch[i] = tolower(ch[i]);

	pstr = strtok(ch, " ");
	fprintf(stdout, "%s\n", pstr);
	
	do
	{
		pstr = strtok('\0', " ");
		if (pstr) fprintf(stdout, "%s\n", pstr);
	}
	while (pstr);

	exit(EXIT_SUCCESS);
}

I greatly simplified what you posted...I hope this will do..It parses the data set but doesn't check for numbers.

gerard4143 371 Nearly a Posting Maven

It may help if you gave us an example of what the resultant query/data set looked like and while your at it, could you show us the definition of test.

gerard4143 371 Nearly a Posting Maven

Try investigating argv[0],,,example

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

#define FILE_EXT ".c"

int main(int argc, char**argv)
{
	char filename[256];
	filename[0] = '\0';

	fprintf(stdout, "argv[0]->%s\n", argv[0]);

	/*strcat(filename, &argv[0][2]);*//*for linux dot slash ./filename*/
	strcat(filename, argv[0]);
	strcat(filename, FILE_EXT);

	fprintf(stdout, "filename->%s\n", filename);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

that would work wouldnt it ??

Yes that wouldn't work, wouldn't it...

gerard4143 371 Nearly a Posting Maven

Here's a very simple example:

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

int main(int argc, char**argv)
{
	int i = 0;
	for (i = 0; i < 5; ++i)
	{
		if (fork())
		{
	
		}
		else
		{
			fputs("Hello, World!\n", stdout);
			exit(EXIT_SUCCESS);	
		}
	}
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

I tried compiling your code over here and it generated a whole pile of errors and warnings when I used these switches

gcc filemane.c -Wall -ansi -pedantic -o filename

It compiled fine when I used

gcc filemane.c -o filename

This statement alone isn't very good...But it did compile and is running without incident.

The output:

server: waiting for connections...
[1] 16980

netstat -a | grep tcp

tcp        0      0 *:mysql-im                  *:*                         LISTEN      
tcp        0      0 *:8998                      *:*                         LISTEN
gerard4143 371 Nearly a Posting Maven

Try this slimmed down server. Will it work/compile on your system if so did it set up a server on port 50000?

#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>
#include <signal.h>

#define DEFAULT_PROTOCOL 0

int main(int argc, char**argv)
{
	int listenfd, connfd;
	struct sockaddr_in servaddr;

	listenfd = socket(AF_INET, SOCK_STREAM, DEFAULT_PROTOCOL);

	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(50000);
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);

	bind(listenfd, (const struct sockaddr*)&servaddr, sizeof(servaddr));

	listen(listenfd, 5);

	for(;;)
	{
		connfd = accept(listenfd, NULL, NULL);

		/*do something server like*/
	}
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Could you print out your netstat output after you run the server

netstat -a | grep tcp

gerard4143 371 Nearly a Posting Maven

Which port(s) are you trying to bind to?

And can we see the code..

gerard4143 371 Nearly a Posting Maven

Try something like this(Or what WaltP said)

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

int main(int argc, char**argv)
{
	int ch;

	fputs("enter a value->", stdout);

	while ((ch = fgetc(stdin)) != '\n')
	{
		if (isdigit(ch))
		{
			fprintf(stdout, "ch is a digit->%c\n", ch);
		}
		else
		{	
			fprintf(stdout, "ch is not a digit->%c\n", ch);
		}
	}

	exit(EXIT_SUCCESS);
}

Now when prompted for a value enter 1q2w3e4r5t6y

gerard4143 371 Nearly a Posting Maven

i want get a number (integer value), and drop out all character, and inform user enter wrong value.

Then you should read what WaltP posted

gerard4143 371 Nearly a Posting Maven
#include <stdio.h>

int main(int argc, const char* argv[])
{

   int x;

   loopstart:
   printf("enter a value : ");
   scanf("%d", &x);
   getchar(); 
   
   printf("value is %d\n", x);
   return 0;

}

can u help me, I want x return integer number (ASCII code) when enter a character...

my code is not working...

thanks...

I'm not sure what your after...Is this it:

#include <stdio.h>

int main(void)
{
	int ch;

	ch = getchar();
	fprintf(stdout, "hex value->0x%x\n", ch);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

i have just started c language and i have only study "while" and "for" "if else"

please help me in this question using loops(without usuing arrays)


write a program that prodeuce the following output:


0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5

#include<stdio.h>
void main(void)
{

int inner;
for(int outer=1;outer<=6;outer++)

{
inner=1;
while(inner<=outer)
{
printf("0");

___________
please help me in this code

What I see from the posted code is...well you need to review the basic structure of a C program...See below

#include <stdio.h>

int main(void)
{
	int inner, outer;

	for (outer = 0; outer <= 6; ++outer)
	{
		for(inner = 0; inner <= outer; ++inner)
		{
			/*do some thing*/
		}
		/*do some thing*/
	}
	return 0;
}

Also - check the tutorial on code tags

gerard4143 371 Nearly a Posting Maven

Narue's version

/*The Narue Version*/
/*As for why I include the extras(exit(EXIT_SUCCESS),int argc, char**argv)...I don't know must be habit*/
#include <stdio.h>

int* myint(void)
{
	static int myint = 9;
	fprintf(stdout, "myint now equals->%d\n", myint);
	return &myint;
}

int main()
{
	*(myint()) = 12356;
	myint();

	return 0;
}
gerard4143 371 Nearly a Posting Maven

What is going on here. Copy this C code , compile and run. What do you think is going on? Note I don't want the answer, I know what's going on here. This is just something for the rookies to play with...

Also this is not the best way to write code...

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

int* myint(void)
{
	static int myint = 9;
	fprintf(stdout, "myint now equals->%d\n", myint);
	return &myint;
}

int main(int argc, char**argv)
{
	*(myint()) = 12356;
	myint();

	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Pointer topic and the use of it totally useless.

If this were true then every program would cease to run...Maybe I misunderstood your posting...

gerard4143 371 Nearly a Posting Maven

Try running this modified version of your program...What happened to the values from the stack?

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

char ch[] = "Don't do this, passing back the value of a local variable is dangerous!";

int * first();

void myfunc(char *s, int x)
{
	fprintf(stdout, "%s, %d\n", ch, x);
}

int main()
{
	int *f;

	f = first();

	printf(" After calling first : value of f ( %p ) \n", (void*)f);
	printf(" After calling first : value of *f ( %x )\n", *f);

	myfunc(ch, 3456);

	printf(" After calling first : value of f ( %p ) \n", (void*)f);
	printf(" After calling first : value of *f ( %x )\n", *f);

	return 0;
}	

int * first()
{
	int f_lcl = 0xAAAA ;
	printf("  In First  : value of f_lcl ( %x ) \n", f_lcl);
	printf(" In First : addr of f_lcl is ( %p ) \n", (void*)&f_lcl); 
	return &f_lcl ;
}

My output:

In First : value of f_lcl ( aaaa )
In First : addr of f_lcl is ( 0x7fffc032a14c )
After calling first : value of f ( 0x7fffc032a14c )
After calling first : value of *f ( aaaa )
Don't do this, passing back the value of a local variable is dangerous!, 3456
After calling first : value of f ( 0x7fffc032a14c )
After calling first : value of *f ( 0 )

gerard4143 371 Nearly a Posting Maven

Try WireShark

gerard4143 371 Nearly a Posting Maven

This addresses every one of your problems...meaning it works.

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

#define NAME "Bob Smith"
int age = 1234;
int bs = 9999999;

int main()
{
	FILE *fd;

	struct emp
	{
		 char name[40];
		 int age;
		 int bs;
	};

	struct emp e, ans;

	memset((void*)&e, 0, sizeof(struct emp));

	if (!(fd = fopen("emp.dat","wb")))
	{
		fputs("could not open emp.dat!\n", stderr);
		exit(EXIT_FAILURE);
	}

	sprintf(e.name, "%s", NAME);
	e.age = age;
	e.bs = bs;

	fwrite(&e, 1, sizeof(struct emp), fd);

	fclose(fd);

	if (!(fd = fopen("emp.dat", "rb")))
	{
		fputs("could not open emp.dat!\n", stderr);
		exit(EXIT_FAILURE);
	}

	fread(&ans, 1, sizeof(struct emp), fd);

	fprintf(stdout, "emp.name->%s\n", ans.name);
	fprintf(stdout, "emp.age->%d\n", ans.age);
	fprintf(stdout, "emp.bs->%d\n", ans.bs);

	fclose(fd);
	exit(EXIT_SUCCESS);
}

Also..

yeah can u take a look at this code ..no error but problem is it retreive only first value of structure ie name and rest as garbage value

Maybe no errors?? The code wouldn't compile...

gerard4143 371 Nearly a Posting Maven

Before you try write or reading the values to/from a file, try printing the values and see if they are correct.

fprintf(stdout, "emp.name->%s\n", e.name);
fprintf(stdout, "emp.age->%d\n", e.age);
fprintf(stdout, "emp.bs->%d\n", e.bs);

And what is this?? To post that here is asking for a flaming war.

fflush(stdin);
gerard4143 371 Nearly a Posting Maven

Basically what is the system level difference between language C and C++ ?

Could you give us an example of what you mean by system level.

gerard4143 371 Nearly a Posting Maven

You have so many errors that I can only guess at what your trying to do...A hint write your program in pieces, making sure each piece works before you proceed to the next....Here's what I think your trying to do...like I said think

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

#define NAME "Bob Smith"
#define AGE "1234"
#define BS "9999999"

int main()
{
	FILE *fd;

	struct emp
	{
		 char name[40];
		 char age[10];
		 char bs[10];
	};

	struct emp e;
	int stsize = sizeof(struct emp);

	memset((void*)&e, 0, stsize);

	if (!(fd = fopen("emp.dat","w")))
	{
		fputs("could not open emp.data!\n", stderr);
		exit(EXIT_FAILURE);
	}

	sprintf(e.name, "%s", NAME);
	sprintf(e.age, "%s", AGE);
	sprintf(e.bs, "%s", BS);

	fwrite(&e, 1, stsize, fd);

	fclose(fd);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Found some other problems

struct emp
		{

		 char name[40];
		 int age[10];
		 int bs[10];
		
	};

and

printf("\n enter age\n");
			scanf("%s",e.age); 
			printf("\n enter salary\n");
			scanf("%s",e.bs);

your scanf functions are using format strings "%s" while your structure defines the variables as integers

gerard4143 371 Nearly a Posting Maven

I could also come up with the correct answer before I ran the program, but it certainly caught my brain for a few minutes.

Yeah when you take something like this program which is out of context...it well looks weird...

gerard4143 371 Nearly a Posting Maven

Only quickly checked but do initial this value...stsize.

My mistake...There it is

stsize=sizeof(struct emp);

gerard4143 371 Nearly a Posting Maven

>Yeah, its was intended for the rookies not the seasoned vets..
Good thing I didn't give away the answer then. ;)

Yeah you were a good sport about that..Thanks

gerard4143 371 Nearly a Posting Maven

PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006
main.c:7: Warning 413: Likely use of null pointer 'iptr' in left argument to operator 'ptr+int'

If that warning is a problem then try:

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

int main(int argc, char**argv)
{
	unsigned long *iptr = (unsigned long*)1;/*pointer equals 1*/
	unsigned long ans = (unsigned long)(iptr + 1);/*add 1 to the pointer*/
	
	fprintf(stdout, "and the answer is->%lu\n", ans);/*whats the answer?*/
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

>Can you predict what the answer will be?
I can certainly try.

>Now run it, were you right?
Yup.

Yeah, its was intended for the rookies not the seasoned vets..

gerard4143 371 Nearly a Posting Maven

One day while pondering about C I came up with this program. Can you predict what the answer will be? Now run it, were you right?


filename.c

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

int main(int argc, char**argv)
{
	unsigned long *iptr = (unsigned long*)0;/*pointer equals 0*/
	unsigned long ans = (unsigned long)(iptr + 1);/*add 1 to the pointer*/
	
	fprintf(stdout, "and the answer is->%lu\n", ans);/*whats the answer?*/
	exit(EXIT_SUCCESS);
}

gcc filename.c -Wall -ansi -pedantic -o filename

gerard4143 371 Nearly a Posting Maven

Thank you..
could you please explain the reason also in detail...

If you want to see the reasoning, try verifying the addresses that your passing.

start with the original address, then verify it in the first function and then verify that its the same in the second function.

gerard4143 371 Nearly a Posting Maven

Here's a little blurb from Linux's 'man make'


6.9 Variables from the Environment
==================================

Variables in `make' can come from the environment in which `make' is
run. Every environment variable that `make' sees when it starts up is
transformed into a `make' variable with the same name and value.
However, an explicit assignment in the makefile, or with a command
argument, overrides the environment. (If the `-e' flag is specified,
then values from the environment override assignments in the makefile.
*Note Summary of Options: Options Summary. But this is not recommended
practice.)

Thus, by setting the variable `CFLAGS' in your environment, you can
cause all C compilations in most makefiles to use the compiler switches
you prefer. This is safe for variables with standard or conventional
meanings because you know that no makefile will use them for other
things. (Note this is not totally reliable; some makefiles set
`CFLAGS' explicitly and therefore are not affected by the value in the
environment.)

When `make' runs a command script, variables defined in the makefile
are placed into the environment of that command. This allows you to
pass values to sub-`make' invocations (*note Recursive Use of `make':
Recursion.). By default, only variables that came from the environment
or the command line are passed to recursive invocations. You can use
the `export' directive to pass other variables. *Note Communicating
Variables to …

gerard4143 371 Nearly a Posting Maven

I hope this link will straighten you out:

http://en.wikipedia.org/wiki/End-of-file

gerard4143 371 Nearly a Posting Maven

This will demonstrate my answer: Take this simple piece of code and compile

gcc -c getsetx.c

unsigned long x = 0;
unsigned long y = 0;

unsigned long gety()
{
	return y;
}

void sety(unsigned long val)
{
	y =  val;
}

unsigned long getx()
{
	return x;
}

void setx(unsigned long val)
{
	x =  val;
}

nm getsetx.o is:

0000000000000022 T getx
0000000000000000 T gety
000000000000002f T setx
000000000000000d T sety
0000000000000000 B x
0000000000000008 B y

and objdump -d getsetx,o is:


getsetx.o: file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <gety>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # b <gety+0xb>
b: c9 leaveq
c: c3 retq

000000000000000d <sety>:
d: 55 push %rbp
e: 48 89 e5 mov %rsp,%rbp
11: 48 89 7d f8 mov %rdi,-0x8(%rbp)
15: 48 8b 45 f8 mov -0x8(%rbp),%rax
19: 48 89 05 00 00 00 00 mov %rax,0x0(%rip) # 20 <sety+0x13>
20: c9 leaveq
21: c3 retq

0000000000000022 <getx>:
22: 55 push %rbp
23: 48 89 e5 mov %rsp,%rbp
26: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 2d <getx+0xb>
2d: c9 leaveq
2e: c3 retq

000000000000002f <setx>:
2f: 55 push %rbp
30: 48 89 e5 mov %rsp,%rbp
33: 48 89 7d f8 mov …

gerard4143 371 Nearly a Posting Maven

the things i dont undestand here is :

1) why the command nm Lib_Symb.o and Main_Symb.o are not having any address refereence, all address are zero there.

2) is there any relation between addresses
in the command nm a.out
because
there are different things that are specifeid at some address
ex : at
08049628 A __bss_start
08049628 b completed.1
08049628 A _edata

what all these specifies .
i understood little bit from the link you provoded .

thanks for the link.
but overall i dint understand completely what actually a symbol table of .0 files (Lib_Symb.o and Main_Symb.o ) consists of and .a.out consists of .

please just give a breif discussion or links
thanks

1. To answer your first question. The files are object files meaning they still have to be linked(assigned addresses) in the final executable so the linking process will assign the memory addresses. The addresses in object files start at zero or are referenced from zero.

Note: Another binary utility you should use is

objdump -D a.out>testfile

gerard4143 371 Nearly a Posting Maven

I modified your code somewhat so you can see what's going on...
1. Run the code below, what values did you get for A, B, C, D, E ?
2. Now un comment the fgetc(stdin) lines and run the code again what are the values now

This should tell you exactly what's going on with your program and why its skipping every second prompt..

#include<stdio.h>

int main()
{
	char A,B,C,D,E ;
	int  AA,BB,CC,DD,EE,res;

	printf("\n1.Who amongst the following is the Head of the RBI at present ?\na.Mr. M.V.Kamath\nb.Mr. Y.V.Reddy\nc.Mr. N.R.Narayanmurthy\nd.Mr.O.P.Bhatt");

	scanf("%c",&A);
	/*fgetc(stdin);*/

	printf("\n2. Mjority of rural people still prefer to go to which of the following for their credit needs ?\na.Money lenders\nb.Foreign Bankers\nc.NABARD\nd.RBI");

	scanf("%c",&B);
	/*fgetc(stdin);*/

	printf("\n3. India has different categories of commercial banks.Which of the following is NOT one such categories ?\na.Private Banks\nb.Commodities Banks\nc.Nationalized Banks\nd.Cooperative Banks");
	 
	scanf("%c",&C);
	/*fgetc(stdin);*/

	printf("\n4.Which of the following countries does not play International Cricket?\na.Russia\nb.England\nc.SouthAfrica\nd.Pakistan");

	scanf("%c",&D);
	/*fgetc(stdin);*/

	printf("\n5.Which is the world’s first credit card?\na.American Express\nb.Visa\nc.Mastercard\nd.Diners Club Card");

	scanf("%c",&E);
	/*fgetc(stdin);*/

	fprintf(stdout, "a->%u\n", A);
	fprintf(stdout, "b->%u\n", B);
	fprintf(stdout, "c->%u\n", C);
	fprintf(stdout, "d->%u\n", D);
	fprintf(stdout, "e->%u\n", E);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

hi,.im a first year student taking information technology, never mind where i am studying.,,,i just want to ask some tips to understand easily turbo c.,.

'Easily understand C' is probably a misnomer but if you have any questions about one of the best programming languages 'C' then fire away...

gerard4143 371 Nearly a Posting Maven

Try googling freopen()...plus here's a small example of redirecting stderr to a file named output.

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

int main(int argc, char**argv)
{
	freopen("output", "w", stderr);

	fputs("send this to stderr\n", stderr);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

how can i read each number and define it as an integer ????

Try googling strtol, strtoll, strtoq - convert a string to a long integer

gerard4143 371 Nearly a Posting Maven

Rules:
• Please solve it on your own/submit your own solution.

What don't you understand about the above rule?

gerard4143 371 Nearly a Posting Maven

What i would like to do is,i want to run a quiz program where the users can see a countdown timer attached to the screen and at the same time should answer my questions.Can you guide me how to do this.Thank tou in advance

This sounds like a candidate for threading. The best thing to do is Google a few thread tutorials, these with some experimenting will determine if threads will work for your program....

gerard4143 371 Nearly a Posting Maven

is it possible in c program to run two processes at the same time.For example i want to run a timer along with my application .The timer must be shown on the screen.Thanks in advance

The short answers is yes with clarification as to what you mean by "same time". Do you mean multi-tasking where the processor appears to be running multiple processes at the same time or do you mean true "same time" where a multi-core processor is required?

With that divergence out of the way check out threads, they allow a single process(or single thread process) to spawn additional processes(or threads/light weight processes).

So yes its possible for a C program to run/spawn more than one process...

Here's a link for POSIX threads

http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

gerard4143 371 Nearly a Posting Maven

I am still in problem. i could not solve the segmentation fault. could anybody know me in more details?

Could you post your updated code..So we can see what you changed.

gerard4143 371 Nearly a Posting Maven

Yes, of course I accept that.. but I'm just learning C and I'm in a bad situation now (no time), so if someone could help me.. it will be great.

anyway, I'm trying to write it alone.. :(

The best thing you could do is post what you have so far and state where your having problems....

gerard4143 371 Nearly a Posting Maven

Lets say I have two functions that I want to run simultaneously for different purposes as example a function handles an XML RPC requests and the other function handles an IRC connection to an IRCD. what my goal would be to avoid program hang ups on user requests. Is pthreads capable of running functions in a way that they won't interfere with each others processing loops? I have been studying them and I seam to be unable to grasp a method that is efficient for processing two sources at once or with least lag. Can you share with me some methods on how you would do it? Try to keep in mind that I am new to C.

Thanks!

The short answer is yes, try looking up mutex and semaphores both of these will protect shared resources from multi access...Threads are inherently dangerous, I heard a saying - "threads are a way for a programmer to shoot himself in both feet at the same time"

http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzahw/rzahwe19rx.htm

gerard4143 371 Nearly a Posting Maven

Hi guys, I'm pretty much a C newbie, but I've dabbled in other languages over the years. For my current project I'm using mikroElektronica Pro C on a PIC microcontroller.

I've got a 2-dimensional array defined like this:

const char FONTTABLE[96][5]= 
{ 
{0x00,0x00,0x00,0x00,0x00}, 
{0x00,0x00,0x5f,0x00,0x00}, 
{0x00,0x07,0x00,0x07,0x00}, 
/** [90 rows snipped] **/ 
{0x00,0x41,0x36,0x08,0x00}, 
{0x10,0x08,0x08,0x10,0x08}, 
{0x78,0x46,0x41,0x46,0x78} 
};

I want to select a given row from this using the index (0-95), then pass that element (a 5 element array) to a routine that will process each byte for the size of the row (5 in this case). I'm pretty sure I need to use a pointer, but no matter what I do I get compile errors.

Any tips?

Try something like below...Note I truncated your array

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

const char FONTTABLE[6][5]= 
{ 
{0x00,0x00,0x00,0x00,0x00}, 
{0x00,0x00,0x5f,0x00,0x00}, 
{0x00,0x07,0x00,0x07,0x00}, 
{0x00,0x41,0x36,0x08,0x00}, 
{0x10,0x08,0x08,0x10,0x08}, 
{0x78,0x46,0x41,0x46,0x78} 
};

int main(int argc, char**argv)
{
	int i = 0, j = 0;

	for (i = 0; i < 6; ++i)
	{
		fprintf(stdout, "row[%d]\n", i);
		for (j = 0; j < 5; ++j)
		{
			fprintf(stdout, " 0x%x", FONTTABLE[i][j]);
		}
		fputs("\n", stdout);
	}
	exit(EXIT_SUCCESS);
}