gerard4143 371 Nearly a Posting Maven

I would investigate a function like

void *memchr(const void *s, int c, size_t n);

The memchr() function scans the first n bytes of the memory area
pointed to by s for the character c. The first byte to match c
(interpreted as an unsigned character) stops the operation.

The memchr() and memrchr() functions return a pointer to the match‐
ing byte or NULL if the character does not occur in the given mem‐
ory area.

Copied from the manpages on GNU/Linux.

With this function you can leap through valid areas of data to store.

gerard4143 371 Nearly a Posting Maven

You define

struct bst root;

and here your allocating memory for it

root=(struct bst*)malloc(sizeof(struct bst));

Why?

gerard4143 371 Nearly a Posting Maven

I literately typed this in google

c++ number to string

and it returned itoa().

http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/

gerard4143 371 Nearly a Posting Maven

Could you please post code using the proper code tags and please format your code.

As for problems, the main function should return an integer and why are you using the getch() function when the standard provides fgetc().

gerard4143 371 Nearly a Posting Maven

Can we see what you have done so far?

gerard4143 371 Nearly a Posting Maven

Your going about this the wrong way. Try using fgets() instead of fgetc().

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

#define STR_SIZE 10

int main(void) 
{
	FILE *fp;
	char ch[STR_SIZE];
	int aInt;
	int bInt;

	fp = fopen("erogol.k","r");

	fgets(ch, STR_SIZE, fp);	
	aInt = atoi(ch);
	fgets(ch, STR_SIZE, fp);	
	bInt = atoi(ch);

	printf("%d \n",bInt+aInt);

	return EXIT_SUCCESS;
}
gerard4143 371 Nearly a Posting Maven

I see a problem right away

char list[9][31];
char sorted[9][31];
//--------Main Program Body----------
cout << "****Alphebetical Sorting Program***"<<endl<<endl;
cout<<"please enter 10 strings you wish to sort"<<endl;

Your arrays are 9 X 31 and should be 10 X 31.

beejay321 commented: wrong comment, i did that and it messed it up, i did what i had originally and it was fine +0
gerard4143 371 Nearly a Posting Maven

Why don't you scan them in as characters e.g.

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

int main()
{
	char ch[3];
	unsigned long myint = 0;
	ch[2] = '\0';

	fscanf(stdin, "%c%c", &ch[0],&ch[1]);

	myint = strtol(ch, NULL, 10);

	fprintf(stdout, "ans->%lu\n", myint);
	return 0;
}

Note this is something you 'never learned' so please don't past it off as your own...Bonus marks should be earned.

WaltP commented: That input is really lame. Why use the bloated fscanf instead of the simple fgetc? -3
gerard4143 371 Nearly a Posting Maven

For starters I would initialize these like so

panvowel.shortest[0] = '\0';
panvowel.longest[0] = '\0';
gerard4143 371 Nearly a Posting Maven

Jeez I tried googling LUA and C++ and found this

http://csl.sublevel3.org/lua/

gerard4143 371 Nearly a Posting Maven

You may want to investigate conio.h or curese.h libraries for this behaviour.

MosaicFuneral commented: No one sane should be using those relics. -1
gerard4143 371 Nearly a Posting Maven

Right away you should include the string.h library for strcpy().

This line

strcpy(a.aStudent->finalMark,bathmos);

Both variables are integers, strcpy requires char pointers.

Your first scanf

scanf("%s",&onoma);

should be

scanf("%s", onoma);
gerard4143 371 Nearly a Posting Maven

You could try something like below:

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

int main(int argc, char**argv)
{
	char mybuf[BUFSIZ];
	FILE *infd;
	FILE *outfd;

	if (!(infd = fopen("infile", "r")))
	{
		fputs("could not open infile!\n", stderr);
		exit(EXIT_FAILURE);
	}
	if (!(outfd = fopen("outfile", "w")))
	{
		fputs("could not open outfile!\n", stderr);
		exit(EXIT_FAILURE);
	}

	while ((fwrite(mybuf, 1, fread(mybuf, 1, BUFSIZ, infd), outfd))){}

	fclose(outfd);
	fclose(infd);
	exit(EXIT_SUCCESS);
}
jephthah commented: we don't do people's homework. -1
gerard4143 371 Nearly a Posting Maven

Try zeroing str[] or declaring it as global...Plus please use fgets() instead of scanf()...Like below

#include<stdio.h>

char str[100];

void reverse(char str[]);

int main()
{
    int i;

    printf("Enter to reverse : ");
    fgets(str, 100, stdin);
    reverse(str);
    return(0);
}
/* Function */

void reverse(char str[])
{

    int i;
    for(i=99;i>=0;i--)
    {
        printf("%c",str[i]);
    }
    putchar('\n');
}
jephthah commented: making it global is not the answer -1
gerard4143 371 Nearly a Posting Maven

>Its urgent
For future reference, stating that your problem is urgent will likely be counterproductive. A lot of us are perverse enough to ignore you solely because you're in a rush.

Sad but true...

WaltP commented: Worthless "me too" post. Please refrain. -2
gerard4143 371 Nearly a Posting Maven

Why can't you send integers with write....

int myint = 1234;

write(fd, (char*)&myint, sizeof(int));
gerard4143 371 Nearly a Posting Maven
void dfs(graph g)
{
	printf("whats wrong with me\n");
	for (int i = 0;i < g.number_vertices;i++)
	{
		g.vertices[i].color = WHITE;
		g.vertices[i].p = NIL;
	}
	time = 0;
	printf("in dfs\n");
	for (int i = 0;i < g.number_vertices;i++)
	{
		if (g.vertices[i].color == WHITE)
		{
//			dfs_visit(g, i);
			printf("i: %d\n",i);
		}
	}
}

Are you sure this is C...Look at the for loop

for (int i = 0;i < g.number_vertices;i++)

gerard4143 371 Nearly a Posting Maven

When you want to left or right shift some bits...or splice some addresses together like below..So when would you need this skill? Hardware programming comes to mind..

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

unsigned long two = 3345;

int main(int argc, char**argv)
{
	unsigned long one = 1234;
	void *addr = (void*)NULL;

	fprintf(stdout, "one addr->%p\n", (void*)&one);
	fprintf(stdout, "two addr->%p\n", (void*)&two);

	/*splice the first 12 bits of two onto the first 12 bits of one*/
	/*and save the result in addr*/

	addr = (void*)(((unsigned long)&one>>12<<12) + ((unsigned long)&two<<52>>52));	

	fprintf(stdout, "result addr->%p\n", addr);
	exit(EXIT_SUCCESS);
}

This was written quickly...I hope its correct..

jephthah commented: ridiculously confusing. -1
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

You need to post 255 lines of code to ask a question about an array of structures?

gerard4143 371 Nearly a Posting Maven

Not sure if this is what your looking for..

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

struct mystr
{
	char ch1[50];
	char ch2[50];
};

void myfunc(struct mystr *str1, struct mystr *str2)
{
	memcpy(&str2->ch1[0], &str1->ch1[0], sizeof(str1->ch1));	
	memcpy(&str2->ch2[0], &str1->ch2[0], sizeof(str1->ch2));		
}

int main(int argc, char**argv)
{
	struct mystr str1 = {"string one", "string two"};
	struct mystr str2;

	fprintf(stdout, "str1 ch1->%s, ch2->%s\n", str1.ch1, str1.ch2);
	fprintf(stdout, "str2 ch1->%s, ch2->%s\n", str2.ch1, str2.ch2);

	myfunc(&str1, &str2);

	fprintf(stdout, "str1 ch1->%s, ch2->%s\n", str1.ch1, str1.ch2);
	fprintf(stdout, "str2 ch1->%s, ch2->%s\n", str2.ch1, str2.ch2);	
	exit(EXIT_SUCCESS);
}
WaltP commented: If it IS what the OP is looking for, why are you GIVING it to him? You should know better. -2
gerard4143 371 Nearly a Posting Maven

I've seen this extension to the language to handle binary constants...you might be able to incorporate it. Notice the number 0b111

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

int main(int argc, char**argv)
{
	fprintf(stdout, "ans->%u\n", 0b111);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

This cleans up the warnings/errors

#include<stdio.h>

int main(){
        char name[25] = "blank", rating[25] = "blank", state[25] = "blank";
        int lobbyists=0, prevemploys=0, number=0;
        double networth=0, tarp=0, contributions=0;

        printf("\n\n(1)Bank name: %s\n(2)State: %s\n(3)Net worth: %f\n", name, state, networth);
        printf("(4)Rating: %s\n(5)TARP money: %f\n(6)Campaign contributions: %f\n", rating, tarp, contributions);
        printf("(7)Lobbyists in capitol: %d\n(8)Previous Employees in government: %d\n", lobbyists, prevemploys);
        printf("\n(9)Display Data\n(10)Clear all Data\n(11)Quit\n\n");

while (number != 11){
        printf("Type the number to edit the field / perform task, and press ENTER: \n\n");
        scanf("%d",&number);
        switch (number) {
                case 1:
                        printf("Enter the name of the bank: ");
                        scanf("%s",name);
                        printf("%s\n\n",name);
                case 2:
                        printf("Enter the name of the state in which this bank is located: ");
                        scanf("%s",state);
                        printf("%s\n\n",state);
                case 3:
                        printf("Enter the bank's net worth: ");
                        scanf( "%lf", &networth);
                        printf("%f\n\n",networth);
                case 4:
                        printf("Enter the bank's rating: ");
                        scanf("%s",rating);
                        printf("%s\n\n", rating);
                default:
                        printf("Please choose one of the desired options' numbers only.");
                }
}
        return 0;
}

You really should get a good book on C

WaltP commented: Now that you've cleaned up the warnings for him, what has he learned? -2
gerard4143 371 Nearly a Posting Maven

I think I understand what you want - try investigating the isdigit() function.

gerard4143 371 Nearly a Posting Maven

Or this one which is a little more exotic - the language lawyers should love this one

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

void Test(char **cptr);

int main()
{
	char *str;
	Test(&str);
	fputs(str, stdout);
	free(str);
	return(0);
}

void Test(char **cptr)
{
	int val = 0;

	printf("How many characters do you want to enter->");
	scanf("%d", &val);
	getc(stdin);

	*cptr = (char*) malloc(val * sizeof(char));

	printf("Enter your text: (DO NOT INCLUDE SPACES)->");
	fgets(*cptr, val, stdin);
}
gerard4143 371 Nearly a Posting Maven

I have this much modified example that you could use for an example:

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

char* Test();

int main()
{
	char *str;
	str = Test();
	fputs(str, stdout);

	return(0);
}

char* Test()
{
	int val = 0;
	char *s;

	printf("How many characters do you want to enter->");
	scanf("%d", &val);
	getc(stdin);

	s = (char*) malloc(val * sizeof(char));

	printf("Enter your text: (DO NOT INCLUDE SPACES)->");
	fgets(s, val, stdin);

	return s;
}
gerard4143 371 Nearly a Posting Maven

Hi everyone,

I recently installed Slackware 13/x86_64 on one of my boxes and now I'm having troubles with Python code that uses threading and Tkinter. This problem never existed on other Linux distro's, it just appeared with Slackware.

The box in question
Acer Athlon x86_64 single core used to run Mandriva/64 and the Python code worked fine.

Now it runs Slackware13/64 and Python threading and Tkinter are not getting along at all(program crashes with out of stack space infinite loop for the thread).

Has anyone experienced anything like this? Any suggestion?...Gerard4143