gerard4143 371 Nearly a Posting Maven

I tried single quotes in your quoted string...it appears to work

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

int main ()
{
	char *ca;
	char queryStringSet[100];
	char command[100];  

	strcpy (command, "export QUERY_STRING=");
	strcpy (queryStringSet, "'a=1&b=2&c=3'");
	strcat (command, queryStringSet);

	printf ("command = %s\n", command);  
	system (command);  

	ca = getenv ("QUERY_STRING"); 
	printf ("QUERY_STRING = %s\n", ca);

	return 0;
}
VernonDozier commented: Thanks. +10
gerard4143 371 Nearly a Posting Maven

Or you could use UDP instead of TCP.
TCP doesn't guarantee packet data size only that it will get delivered in order...like you said if you want to extract individual messages then you'll have to figure out an application protocol to handle it..

gerard4143 371 Nearly a Posting Maven

Try something like below

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

int main(int argc, char**argv)
{
	int ch = 0, i = 0;
	FILE *fd;

	if (!(fd = fopen("filename", "r")))
	{
		fputs("could not open file!\n", stderr);
		exit(EXIT_FAILURE);
	}

	while ((ch = fgetc(fd)) != EOF)
	{
		if (ch == '\n')
			++i;
	}

	fprintf(stdout, "the number of lines->%d\n", i);

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

I'm assuming this is a text file - Why don't you check for the newline character '\n'

gerard4143 371 Nearly a Posting Maven

shouldn't this

sscanf(buffer, "%lf", tempFinal

be

sscanf(buffer, "%lf", &tempFinal
Iamthedude commented: Thanks for the help +0
gerard4143 371 Nearly a Posting Maven

Try something like below:

.section .data
    v1: .byte 1, 2, 3, 4, 1, 2, 3, 4
    v2: .byte 1, 5, 5, 5, 5, 5, 5, 5

.section .bss

.section .text
	.global _start
_start:
	movq	v1, %mm0
	movq	v2, %mm1	

	pcmpeqb %mm0, %mm1
	movq	%mm1, %rdi

	movq	$60, %rax
	syscall

the answer in %mm1 is ff 00 00 00 00 00 00 00

For your example you would use to test your vector for twos

.section .data
    v1: .byte 1, 2, 3, 4, 1, 2, 3, 4
    v2: .byte 2, 2, 2, 2, 2, 2, 2, 2

.section .bss

.section .text
	.global _start
_start:
	movq	v1, %mm0
	movq	v2, %mm1	

	pcmpeqb %mm0, %mm1
	movq	%mm1, %rdi

	movq	$60, %rax
	syscall
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

when i restart my PC to see weather my module is printing ' Hello World ' or not its not res poncing any thing

That's because you ismod'd the module. You have to inform the kernel at boot up that you want the module inserted.

Take a look at this link:

http://www.cyberciti.biz/faq/linux-how-to-load-a-kernel-module-automatically-at-boot-time/

gerard4143 371 Nearly a Posting Maven

I'm not sure why you need to force the users to call init()- a well commented header file or docs should suffice or is this part of the assignment requirements..

gerard4143 371 Nearly a Posting Maven

execve info/man has really good example code towards the bottom of the topic.

Here's what I did:

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

int main(int argc, char *argv[])
{
	char *newargv[] = { "/bin/ls", "-l", NULL };
	char *newenviron[] = { NULL };
	char *exeprog = "/bin/ls";

	execve(exeprog, newargv, newenviron);

	exit(EXIT_FAILURE);
}

Like I said check the bottom of execve info/man for the example code...

gerard4143 371 Nearly a Posting Maven

Hello Friends,
I have a small IP scan code written in shell script,i want my code should get executed as kernel get booted....plz tell how can i insert that code into new kernel...what are the steps should i follow.....

The only thing that you can insert into a Linux kernel are kernel modules which are written in C.

Check out this link:

http://tldp.org/LDP/lkmpg/2.6/html/

If you want to execute the script on boot then that's a different story.

http://www.linuxforums.org/forum/redhat-fedora-linux-help/24951-start-script-boot.html

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

I tried looking at the code and got to the function

void populate_array_from_text_file(char array_strings[][LETTERS_PER_WORD], char file_name[])

where the program opens a file without checking to see if it succeeded and then reads from that file without checking for EOF.....

Any ways here's a cleaner posting of the code...by the way, why do you this is some parts of your code - return & break

else if(str1[result]=='\0' && str2[result] == '\0')
		{	
			return 0;
			break;
		}

Plus this little odd ball

if    (compare_two_letters_case_insensitive(str1[i],str2[i]) == 1)           
		{
			;
		}

cleaner posting

#define WORDS_IN_DICT words_in_file(DICT)
#include<stdio.h>
#define WORD_AMOUNT 5
#define LETTERS_PER_WORD 10
#define CASE_OFFSET 32
#define DICT "dictionary.txt"
#define INPUT "input.txt"
#include <stdlib.h>

void swap_words(char word1[], char word2[]);

void copy_from_first_to_second(char word1[], char word2[]);

void organize_words_alphabetically(char array_words[][LETTERS_PER_WORD],int words_in_array);

int compare_two_letters_case_insensitive(char letter1, char letter2);

void populate_array_from_text_file(char array_strings[][LETTERS_PER_WORD], char file_name[]);

int compare_strings_case_insensitive(char str1[], char str2[]);

void print_all_words(char array_words[][LETTERS_PER_WORD], int word_amount);

int words_in_file(char file_name[]);

int compare_strings(char str1[], char str2[]);

void verify_all_input_file_words_in_dictionary (char input_words[][LETTERS_PER_WORD],char dictionary_file[], char input_file[], int word_amount);

int is_word_in_dictionary(char word[], char file_name[]);


void start_program() ;

int words_in_new_array = 0; 
	
int main(void)
{
	start_program() ;
	return 0;
}


void start_program()
{
	char input_words[WORD_AMOUNT][LETTERS_PER_WORD]={{0},{0}}; 

	printf("\nVerifying which words aren't in file:\n\n") ; 

	verify_all_input_file_words_in_dictionary(input_words,DICT,INPUT, WORD_AMOUNT); 

	organize_words_alphabetically(input_words,words_in_new_array) ; 

	printf("\nShowing words found that are in file:\n"); 

	print_all_words(input_words, words_in_new_array);

	printf ("\n") ;
	system ("pause") ;
}


void verify_all_input_file_words_in_dictionary(char input_words[][LETTERS_PER_WORD],char dictionary_file[], char input_file[], int word_amount)
{	
	int i;
	char array_from_input[WORD_AMOUNT][LETTERS_PER_WORD];

	populate_array_from_text_file(array_from_input,input_file);

	for(i = 0; i < word_amount; i++)                                                   
	{	
		if  (is_word_in_dictionary(array_from_input[i], dictionary_file) == 0)
		{
			printf("-The word \"%s\" …
gerard4143 371 Nearly a Posting Maven

Measuring execution time is a very complex task...just check the link titled

[pdf]Measuring Program Execution Time


http://www.google.ca/#hl=en&source=hp&q=linux+execution+time&btnG=Google+Search&meta=&aq=1&oq=linux+execu&fp=7e102d89cbdc458f

gerard4143 371 Nearly a Posting Maven

Okay that makes some sense. How come I have to use a pointer to a pointer? Why can't I just use regular char?

Also, I he said specifically that he wanted the state to be saved as "an 8-bit integer, 0 = Alabama,…49 Wyoming." But a regular int is only saved as 4 bits or something like that.

How come I have to use a pointer to a pointer? Why can't I just use regular char?

You have to use a pointer to a pointer because the function call will make a copy of it on the stack and you want the address of the char pointer to get the const char * value.

For the integer value you could use char instead of int, it really doesn't matter.

gerard4143 371 Nearly a Posting Maven

Not sure what you mean by this line - "remove a consecutive occurrence of white space character". Do you mean remove all the spaces in a line of text? Because if that's your intent then try looking up the "C squeeze algorithm".

gerard4143 371 Nearly a Posting Maven

My question is Y DLL? i know that it saves memory and many process can use 1 DLL file at a time blah blah blah......

but is there any task which can not b achieved without using DLL files?? Please reply in details.

I never understood the logic or lack of it in postings like these...You asked questions like - "My question is Y DLL?" and have statements like "can not b achieved" and "blah blah blah......" and you expect a coherent reply with details.

gerard4143 371 Nearly a Posting Maven

I tried this and it worked:

file1.h

#define USD 1

file2.h

#define UKP 1

file3.c

#include<stdio.h>
#include "file1.h"
/*#include "file2.h"*/


#ifdef USD
	#define curr 46
#endif

/*#ifdef UKP
	#define curr 100
#endif*/
int main()
{
	int rs;
	rs = 10 * curr;
	printf ( "ans->%d\n", rs);
	return 0;
}

program output:
ans->460

gerard4143 371 Nearly a Posting Maven

I never used SQLite3 but I'm going to say yes because when I googled SqLite3 it said this...

Cross-platform C library that implements a self-contained, embeddable, zero-configuration SQL database engine. The site offers user and developer ...

Why would you need C wrapper functions for a C library?

gerard4143 371 Nearly a Posting Maven

If your into nasm then try this site

http://www.tortall.net/projects/yasm/

gerard4143 371 Nearly a Posting Maven

456 lines of code - That is the best you can do. You can't narrow the problem to a certain section of this program?

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

Are you kidding...narrow it down to an operating system plus area of programming..

gerard4143 371 Nearly a Posting Maven

I think this is what you want:

main.c

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

#define APP_PATH "/path_to_testit/testit"

int main(int argc, char**argv)
{
	if (fork())
	{
		fprintf(stdout, "parent pid->%d\n", getpid());
	}
	else
	{
		execlp(APP_PATH, APP_PATH, "some value");
	}
	exit(EXIT_SUCCESS);
}

testit.c

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

int main(int argc, char**argv)
{
	fprintf(stdout, "we passed->%s\n", argv[1]);
	fprintf(stdout, "client's parent->%d\n", getppid());
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Yes use fork then execlp(or one of the family of functions from exec).

gerard4143 371 Nearly a Posting Maven

Try this, you had a typo in your array - 'a','b','c','e','d','e','f','g' - giving you excess elements plus a few more errors

#include <stdio.h>

int main(int argc, char** argv)
{
	char c[999];
	char alpha[2][26]={{'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'},{'a','b','c','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}};
	int pos[26];
	int i=0;
	for(i=0;i<26;i++)
	{
		printf("%c\n",alpha[0][i]);
	}
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Tried adding some data...or functions in this case

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

char ch[] = "this is the string!\n";

typedef char* (*firstptr)(void);
typedef firstptr (*secondptr)(void);

char* retstr(void)
{
	return ch;
}

firstptr retfunc(void)
{
	return retstr;
}

int main(int argc, char**argv)
{
	secondptr myarray[10];
	myarray[0] = retfunc;
	fprintf(stdout, "ch->%s\n", ((firstptr)myarray[0]())());

	exit(EXIT_SUCCESS);
}

The output:
ch->this is the string!

Salem commented: Very nice, using a couple of intermediate typedefs +19
gerard4143 371 Nearly a Posting Maven

This might be right, then again I may have read your posting wrong

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

typedef char* (*firstptr)(void);
typedef firstptr (*secondptr)(void);

int main(int argc, char**argv)
{
	secondptr myarray[10];
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Here is a simple example to show static functions. The qualifier "static" is an instruction to the linker - meaning its only visible to other functions in the same file.

getaddress.c

#include <stdio.h>

typedef void (*pfunc)(void);

static void myfunc(void)
{
	fputs("Hello, World!\n", stdout);
}

pfunc getaddr(void)
{
	return myfunc;
}

getaddress.h

typedef void (*pfunc)(void);

pfunc getaddr();

mainprog.c

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

int main(int argc, char**argv)
{
	pfunc tfunc = getaddr();
	tfunc();
	/*myfunc();*//*won't compile if we remove the comments*/
	exit(EXIT_SUCCESS);
}

gcc -Wall -ansi -pedantic -c getaddress.c
gcc mainprog.c getaddress.o -Wall -ansi -pedantic -o mainprog

Program output:
Hello, World!

gerard4143 371 Nearly a Posting Maven

Hi,

Where does a static function reside? We know that static variables reside in BSS. So does a static function also reside in any particular place? Again is there any classification of functions like there is for data like heap, stack, BSS.

Moreover, is function pointer similar to data pointer? I mean it is difficult to imagine the existence of a pointer to code fragment. What does a function pointer really points to? What kinds of operations are permitted on function pointers?

Thanks.

Not sure what you mean by BSS, do you mean the bss section in assembler - block started by symbol? Because if you do, then your above statement isn't true.

Where does a static function reside?
The same place a non-static function resides its just not visible outside of the file its created in.

Moreover, is function pointer similar to data pointer?
Yes in the very low-level way they are the same, just an address but when you look at pointer in a high level language then you have differences...example:

In C its very reasonable to do this:

int *x = (unsigned int*)malloc(sizeof(int));

which allocates memory for an integer...

but if we were to try

typedef void(*pfunc)(void);
pfunc tfunc = (pfunc)malloc(sizeof(pfunc));

it would be ridiculous because you can't allocate a function using malloc

So yes we do have differences in function pointers and data pointers in high level languages.

gerard4143 371 Nearly a Posting Maven

I would open the file and read three lines into it and then display the results...This sounds like a for loop to me..

gerard4143 371 Nearly a Posting Maven

Here's a simple hint on code writing...Get one piece working before you move onto the next piece of code...Your code has all the characteristics of someone guessing at the answers

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

void getfname(char *line);

int main(void)
{
	char fInput[256];
	char fOutput[256];

	int fd, fd2;
	printf("input file:  ");
	getfname(fInput);
	printf("output file: ");
	getfname(fOutput);


	if((fd = open(fInput, O_RDONLY)) < 0)
	{
		perror(fInput);
		exit(1);
	}


	if((fd2 = open(fOutput, O_WRONLY|O_CREAT, 0666)) < 0)
	{
		perror(fOutput);
		close(fd);
		exit(1);
	}

	exit(EXIT_SUCCESS);
}
void getfname(char *line)
{
	fscanf(stdin, "%s", line); 
}

Very important - Do you know why this works now?

gerard4143 371 Nearly a Posting Maven

Try changing this line

fgets(line, PATH_MAX, stdin);

to

fscanf(stdin, "%s", line);

Will your program open the files now?

gerard4143 371 Nearly a Posting Maven

Could we see what you have so far?

gerard4143 371 Nearly a Posting Maven

it is useless for me now, the project deadline past. But you can share it It will be harmless for me I will use in a virtual system and harmless for others because I think to execute the module, you must be root. Whatever thx for reply, Gerard.

I think your missing the point, I don't like the idea of posting "nuisance" code, code that can be used for malicious purposes...

gerard4143 371 Nearly a Posting Maven

Ancient Dragron mentioned strtok...I would explore that option...Here's what I came up with in a few minutes of playing around...

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

char ch[] = "this is a string of text for testing purposes and only for testing";

int main(int argc, char**argv)
{
	int i = 0;
	int len = strlen(ch);
	char *str = &ch[0];
	char *end = &ch[len];
	char *endpos = end;

	while (end-- != str)
	{
		if (end[0] == ' ')
		{
			for (i = 1; i < (endpos - end); ++i)
			{
				fprintf(stdout, "%c", end[i]);
			}
		endpos = end;
		fputc(' ', stdout);		
		}
	}
	fputs("\n", stdout);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

As i did in my first post, i meant by using recursive function calls.... when we call a function recursively , it will automatically push the local variables to stack right?
in my case , to print in reverse order, i thought recursion would be suffiecient

You mentioned optimized in your first posting, then calling a function recursively is probably not the way because of the overhead generated by each function call..

gerard4143 371 Nearly a Posting Maven

I can make my intterrup handler (IRQ) but if I change the original interrupt handler, the computer must be rebooted or I must made the interrupt handler, the original handler from my handler and I don't know whether that is can be done in kernel 2.6.x

You didn't make it - Peter Jay Salzman and Ori Pomerantz made the module your just trying to expand it into a keylogger.
Check this site - http://www.faqs.org/docs/kernel/x1206.html

Can it be done? Yes, because I have done it in Linux 2.6.x. Am I going to give you the code? No because its a pure hack that would involve to much tutoring and time to explain what I did..Plus I don't believe in this type programming, its counter-productive and accomplishes nothing in the end, so why did I do it...because they said it couldn't be done and I was up to the challenge...but in the end I won't post this type of code because I categorize it as nuisance code that benefits no one..

gerard4143 371 Nearly a Posting Maven

Could we see some code...Your array, what type is it?

gerard4143 371 Nearly a Posting Maven

Linux man states

CONFORMING TO
Both getline() and getdelim() are GNU extensions. They are available
since libc 4.6.27.

gerard4143 371 Nearly a Posting Maven

Hi,

I m working in c and unix...

Help me out how to become an expert in c programming....

suggest some website link, tutorials and books...for both c and unix..

Thanks,
Nshh.

The C programming Language by Kerninghan and Ritchie
The Complete Reference C by Schildt

gerard4143 371 Nearly a Posting Maven

did you try displaying the value of int check, just to be sure its what you expect it to be?

void CRC(int check)
{
/*display check here*/
	if (check != 0)
	{												printf("NOT Corrupted");
	}
	else
	{
		printf("Corrupted");
	}
// return 0;
	
}

Your not really give us much to work with..

gerard4143 371 Nearly a Posting Maven

Try this as a template for starting your code

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

#define BLK_SIZE 25

int main()
{
	char ch[BLK_SIZE + 1];
	int n = 0;

	int fd = open("filename", O_RDONLY);
	if (fd < 0)
	{
		fputs("could not open filename!\n", stderr);
		exit(EXIT_FAILURE);
	}

	while ((n = read(fd, ch, BLK_SIZE)) > 0)
	{
		ch[n] = '\0';
		/*if you want to see the read results then uncomment the next line*/
		/*fprintf(stdout, "\nread->%d\n", n);*/
		write(1, ch, n);
	}

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

Or you could:

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

int main()
{
	char *cptr = NULL;
	size_t thesize = 0;
    
	while(1)
	{
	    if(feof(stdin) != 0)
	    { break; }
	    
	    getline(&cptr, &thesize, stdin);

	    printf("input string is : %s\n", cptr);

		free(cptr); 
		cptr =  NULL;           
	}

	getc(stdin);
    return 0;
    
}
gerard4143 371 Nearly a Posting Maven

Try something like below:

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

int main()
{

	char inputstr[128];
	char *cptr = &inputstr[0];
	size_t thesize = 128;
    
	while(1)
	{
	    if(feof(stdin) != 0)
	    { break; }
	    
	    getline(&cptr, &thesize, stdin);

	    printf("input string is : %s\n", inputstr);            
	}

	getc(stdin);
    return 0;
    
}
gerard4143 371 Nearly a Posting Maven

hi guy i started learning c recently, and im trying to do exercises from the book the bad thing is they are not showing the solutions.
what i need to do is simply modify the program below so that instead of reading single characters at a time, it reads in blocks of text at a single go, and then displays the block on screen.
im not very sure how to make it work...:/

// read the file from comand lien and displys it
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

main(int argc, char *argv[])
{
  int fd ,numseats, i=0;
  
  fd = open(argv[1],O_RDWR);
  
  if(fd <0)
    {
      printf("file s% not found",argv[1]);
      exit(1);
    }

  while(read(fd, &numseats, sizeof(int)) > 0)
    printf("flight%4d: %4d seats available\n",
	   i++, numseats);
  
  /* finished */
  exit(0);
}

also it asks me to let the user choose where the output could be sent to whether screen or specified file.
i hope you could help me with this
thanks a lot guys in advance

You are reading blocks of text - the blocks just happen to be the sizeof int

read(fd, &numseats, sizeof(int))

For a choice of output use the write system call

ssize_t write(int fd, const void *buf, size_t count);
gerard4143 371 Nearly a Posting Maven

I'm implementing a TCP protocol. TCP implementation requires to send packets continuously and if the receiver doesnt respond after a particular interval of time it should resend the packet again. I need some method to implement a timer expiry function. How can I implement it?? Should i implement threads (If yes can you please give a sample)? or is there any better method?

Btw I'm implementing it in a Unix system

Everything you mention here is already incorporated into TCP/IP..

gerard4143 371 Nearly a Posting Maven

Could you show us what you have so far...

Salem commented: They just did! ;) It's just not enough. +18
gerard4143 371 Nearly a Posting Maven

Here's a quick and simple version of what your trying to do:

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

struct words 
{
	char word[255];
	int count;
	struct words *next;
} *pointer, *start;

int statistics();
    
int main(void)                                                                               
{
	statistics();
	return 0;   
}

int statistics()
{   
	FILE *fp;
	int a;
	char quest[255];

	fp=fopen("name", "r");

	fscanf(fp, "%s", (char*)&quest[0]);

	pointer = (struct words *)malloc(sizeof(struct words));
	start = pointer;

	if(pointer == NULL)
		return 0;

	strncpy(pointer->word, quest, 255);
	pointer->next = NULL;
	++pointer->count;


	while(( a = fscanf(fp, "%s", (char*)&quest[0]))!= EOF)
	{
		pointer->next = (struct words *)malloc(sizeof(struct words));
		/*should check allocation*/
		pointer = pointer->next;
		pointer->next = NULL;
		++pointer->count;
		strncpy(pointer->word, quest, 255);
	}

	pointer = start;
	
	while (pointer->next)
	{
		fprintf(stdout, "word->%s, count->%d\n", (char*)&pointer->word[0], pointer->count);
		pointer = pointer->next;
	}
	fprintf(stdout, "word->%s count->%d\n", (char*)&pointer->word[0], pointer->count);

/*free allocated linked list or comment your letting the program's exit routine
frre any allocated memory*/
    return 0;
}

Note it doesn't count the words - I'll leave that part to you
Also its been a while since I looked linked list....you might want to go over this code with a fine tooth comb..

Also - forgot, you should free the allocated linked list in the int statistics() function....the very least you should put in comments indicating that the program is short running(a once through) and your letting the program's exit routine free the linked list

gerard4143 371 Nearly a Posting Maven

Here's a quick and simple version of what your trying to do:

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

struct words 
{
	char word[255];
	int count;
	struct words *next;
} *pointer, *start;

int statistics();
    
int main(void)                                                                               
{
	statistics();
	return 0;   
}

int statistics()
{   
	FILE *fp;
	int a;
	char quest[255];

	fp=fopen("name", "r");

	fscanf(fp, "%s", (char*)&quest[0]);

	pointer = (struct words *)malloc(sizeof(struct words));
	start = pointer;

	if(pointer == NULL)
		return 0;

	strncpy(pointer->word, quest, 255);
	pointer->next = NULL;
	++pointer->count;


	while(( a = fscanf(fp, "%s", (char*)&quest[0]))!= EOF)
	{
		pointer->next = (struct words *)malloc(sizeof(struct words));
		/*should check allocation*/
		pointer = pointer->next;
		pointer->next = NULL;
		++pointer->count;
		strncpy(pointer->word, quest, 255);
	}

	pointer = start;
	
	while (pointer->next)
	{
		fprintf(stdout, "word->%s, count->%d\n", (char*)&pointer->word[0], pointer->count);
		pointer = pointer->next;
	}
	fprintf(stdout, "word->%s count->%d\n", (char*)&pointer->word[0], pointer->count);
    return 0;
}

Note it doesn't count the words - I'll leave that part to you
Also its been a while since I looked linked list....you might want to go over this code with a fine tooth comb..