-1

I would investigate a function like

[code]
void memchr(const void s, int c, size_t n);
[/code]
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.

-1

I see a problem right away

[code]
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;
[/code]

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

Votes + Comments
wrong comment, i did that and it messed it up, i did what i had originally and it was fine
-1

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

[code]

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;

}
[/code]

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

Votes + Comments
That input is really lame. Why use the bloated fscanf instead of the simple fgetc?
-1

You could try something like below:

[CODE]

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);

}
[/CODE]

Votes + Comments
we don't do people's homework.
-1

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

[CODE]

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');

}
[/CODE]

Votes + Comments
making it global is not the answer
-1

[CODE]
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);
}
}
}
[/CODE]

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

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

-1

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..

[CODE]

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);

}
[/CODE]

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

Votes + Comments
ridiculously confusing.
-1

Not sure if this is what your looking for..

[CODE]

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);

}

[/CODE]

Votes + Comments
If it IS what the OP is looking for, why are you GIVING it to him? You should know better.
-1

This cleans up the warnings/errors

[CODE]

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;
}
[/CODE]

You really should get a good book on C

Votes + Comments
Now that you've cleaned up the warnings for him, what has he learned?
-2

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

[CODE]

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);

}
[/CODE]

-2

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

[CODE]

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;

}
[/CODE]

-1

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