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 looking at the macro BUFSIZ.

I found this about BUFSIZ

Macro: int BUFSIZ
The value of this macro is an integer constant expression that is good to use for the size argument to setvbuf. This value is guaranteed to be at least 256.

The value of BUFSIZ is chosen on each system so as to make stream I/O efficient. So it is a good idea to use BUFSIZ as the size for the buffer when you call setvbuf.

Actually, you can get an even better value to use for the buffer size by means of the fstat system call: it is found in the st_blksize field of the file attributes. See section 14.9.1 The meaning of the File Attributes.

Sometimes people also use BUFSIZ as the allocation size of buffers used for related purposes, such as strings used to receive a line of input with fgets (see section 12.8 Character Input). There is no particular reason to use BUFSIZ for this instead of any other integer, except that it might lead to doing I/O in chunks of an efficient size.

gerard4143 371 Nearly a Posting Maven

Is this a C or Cpp progect? If its a C project try including the string.h header.

gerard4143 371 Nearly a Posting Maven

hi,
i i recently installed dev c++ 4.9.9.2 ....the first hello world program i wrote gave me some insane messages when i compiled & the exe files which gets created...my antivirus detects them as trojan flies & deletes them....i tired & re -installed dev again but it didnt help...please help me guys...here are the messages i get

1 F:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31
1 E:\C & C++\k.cpp from E:\C & C++\k.cpp
32:2 F:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

Don't use iostream.h use iostream...Plus if your using iostream this should be posted in the C++ section.

gerard4143 371 Nearly a Posting Maven

why is there a + infront of 100k but a - infront of 500k?

You really should familiarize yourself with manpages

TESTS
       Some  tests,  for  example  -newerXY  and  -samefile,  allow comparison
       between the file currently being examined and some reference file spec‐
       ified  on the command line.  When these tests are used, the interpreta‐
       tion of the reference file is determined by the options -H, -L  and  -P
       and any previous -follow, but the reference file is only examined once,
       at the time the command line is parsed.  If the reference  file  cannot
       be  examined  (for  example,  the stat(2) system call fails for it), an
       error message is issued, and find exits with a nonzero status.

       Numeric arguments can be specified as

       +n     for greater than n,

       -n     for less than n,

       n      for exactly n.
gerard4143 371 Nearly a Posting Maven

The best way to understand Linux/Unix is the shell and shell programming. If you have a solid understanding of how these features work...Then you have a solid understanding of Linux/Unix.

gerard4143 371 Nearly a Posting Maven

Close enough....

gerard4143 371 Nearly a Posting Maven

Did you try investigating setjmp, longjmp.

Also sometimes, for efficiency, goto's are the best solution.

gerard4143 371 Nearly a Posting Maven

Here's what manpages has to say about return values for fcsanf()

RETURN VALUE
These functions return the number of input items successfully matched
and assigned, which can be fewer than provided for, or even zero in the
event of an early matching failure.

The value EOF is returned if the end of input is reached before either
the first successful conversion or a matching failure occurs. EOF is
also returned if a read error occurs, in which case the error indicator
for the stream (see ferror(3)) is set, and errno is set indicate the
error.

gerard4143 371 Nearly a Posting Maven

I tried googling 'C programming exercises' and got a page full of results.

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

Try running this code...

#include<stdio.h>
struct converter {
   unsigned short int i;
};
main() {
   struct  converter * converts;
   char a[9]="12345678\0";
   converts = (struct converter*) (a + 0);

   printf("12 is printed %p\n", ntohs(converts->i));
}

it produces - 12 is printed 0x3132
Where 0x31 and 0x32 are the ascii values of 1 and 2

Also manpages has this to say about ntohs

htonl, htons, ntohl, ntohs - convert values between host and network
byte order

gerard4143 371 Nearly a Posting Maven

Hi all,

the following code prints garbage values. I want to read from an array two bytes and print then as a short int after doing ntohs.
What is the bug in the code?

Thanks and Regards,
Prashanth

#include<stdio.h>
struct converter {
   unsigned short int i;
};
main() {
   struct  converter * converts;
   char a[9]="12345678\0";
   converts = (struct converter*) (a + 0);

   printf("12 is printed %u\n", ntohs(converts->i));
}

You realize that ch[9] is an array of characters not integers.

gerard4143 371 Nearly a Posting Maven

cvs files are comma delimited right? You may have to set the sort delimiter with -t

gerard4143 371 Nearly a Posting Maven

I am nt getting the desired out put here! I am still getting the duplicates...

my requirement is copare each and every first filed..

when i executed this i am getting three records:

awk 'x[$1]++ == 1 { print $1 " is duplicated"}' inputfile.cvs

is there anyway to compare only first field and print full data...

That's because awk is reading the file. You need to have sort read the file and pipe the results to awk...Like I showed you in the above postings.

gerard4143 371 Nearly a Posting Maven

Actually, I am new to shell scriting.
you mean to say:

sort -u | awk '!x[$0]++' $1 > results-new.cvs

Almost $1 belongs with the sort command

sort -u $1 | awk '!x[$0]++'   > results-new.cvs

I never used VB script. It looks extravagant.

The worst thing you can do while bash shell scripting is think like a 'traditional' programmer. Things are done differently in bash scripting.

gerard4143 371 Nearly a Posting Maven

Like this..

#!/bin/sh
if [ $# -ne 1 ]
then
	echo "Usage - $0  file-name"
	exit 1
fi

touch results.cvs

if [ -f $1 ]
then
	echo "$1 file exist"
	sort -u $1 | awk '!x[$0]++' > results.cvs
else
	echo "Sorry, $1 file does not exist"
fi

Note - You really should have the proper exits in your program.

gerard4143 371 Nearly a Posting Maven

I have file which is having large data in it. and there are some repeated rows. Basic idea here is : Sort data, remove duplicates based on first field and then print the whole....

I have tried teh following but no help..

#!/bin/sh
if [ $# -ne 1 ]
then
    echo "Usage - $0  file-name"
    exit 1
fi
if [ -f $1 ]
then
    echo "$1 file exist"
    sort -u $1 > results.cvs
    awk '!x[$0]++' results.cvs > results-new.cvs
 else
    echo "Sorry, $1 file does not exist"
fi

Input data and expected out put data Attached :

trying in HP-UNIX

Actually looking at your script, you have sort...
Why are you using a temp file results.cvs. Won't it make more sense to pipe the result of sort directly into awk.

gerard4143 371 Nearly a Posting Maven

I would use the sort utility for this one..

gerard4143 371 Nearly a Posting Maven

This in from the manpages

1. How can I list just the names of matching files?

grep -l 'main' *.c

lists the names of all C files in the current directory whose
contents mention `main'.

So this should open each one in vi
vi grep -l 'main' *.c

Actually on my system I found this works.

vim $(grep -l 'main' *.c)

gerard4143 371 Nearly a Posting Maven

Maybe if you gave us an example of filenames and then the filtered list.

gerard4143 371 Nearly a Posting Maven

hm . . . so if my cgi file which opens up html templates, that means that execve() will run the cgi file (which it does) but the html templates the cgi file runs will come out as text and not code.

Here's my 'limited' understanding of CGI. A client requests something from a web server, the web server runs CGI script/executable which formats a html web page which is then beamed over to the web client who then views/accepts it in a web browser....

gerard4143 371 Nearly a Posting Maven

I always understood that's what its supposed to do...generate web script or pages.

gerard4143 371 Nearly a Posting Maven

Your missing a '}' in your if statement. Check right before the else.

gerard4143 371 Nearly a Posting Maven

You could try this site:

http://www.freebyte.com/programming/assembler/

You might get lucky

gerard4143 371 Nearly a Posting Maven

Is there a difference between

%ecx and (%ecx)

I don't really care at this point about specific register uses, just consider %ecx a general purpose register for my question.

I know that if you have a base pointer (%ebp) and you want to reference a location based on that, you can write something like

8(%ebp) (for the first argument given in a function)

but when dealing with registers like %edx, what would one use parenthesis for?

Yes...The first is the value in the register - %eax
and the second is dereferencing the value in the register - (%eax)

Example of the second use
If %eax contains a memory address then (%eax) will retrieve the value located at that memory address and 8(%eax) will retrieve the value at memory address + 8.

gerard4143 371 Nearly a Posting Maven

I wrote this simple program to demonstrate how the exec family of functions behave:
testp.c

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

int main(int argc, char**argv)
{
	execlp(argv[1], argv[1], NULL);
	fprintf(stdout, "failed\n");
	exit(EXIT_SUCCESS);
}

Usage: execute program with a valid shell executable say ps

./testp ps

Then execute with a bogus shell executable say pssssp

./testp pssssp

gerard4143 371 Nearly a Posting Maven

does it print "program done" and return 0?

Which one..The program forks

gerard4143 371 Nearly a Posting Maven

I mean I want to take a c variable and be able to use it in a script

The check out

NAME
setenv - change or add an environment variable

SYNOPSIS
#include <stdlib.h>

int setenv(const char *name, const char *value, int overwrite);

int unsetenv(const char *name);

SEE ALSO
clearenv(3), getenv(3), putenv(3), environ(7)

I'm assuming you want to pass values to the shell script..Are you talking about some shared memory scheme where the script has access to the C program's memory?

gerard4143 371 Nearly a Posting Maven

Hey so I'm trying to get one of my c variables to be a bash variable. Is there a way that I can do this?

Exactly what do mean by 'to be a bash variable'. Do you mean the variable is shared between the C program and the shell or do you mean passing values between the C program and the shell script...

gerard4143 371 Nearly a Posting Maven

Here's what the manpages have to say...

RETURN VALUE
If any of the exec() functions returns, an error will have occurred.
The return value is -1, and errno will be set to indicate the error.

gerard4143 371 Nearly a Posting Maven

What was the error messages?

gerard4143 371 Nearly a Posting Maven

When stating a question, it should be prominent in your postings not included with a line like:

I also want to know the whole business of man page

Which indicates that this is the secondary question not the primary.

About your question check out his link

http://linux.omnipotent.net/article.php?article_id=12493&page=1

Which I arrived at by typing in firefox "linux creating man pages"

gerard4143 371 Nearly a Posting Maven

You should take a look at this link, You'll find manpages has 8 sections

http://linuxmanpages.com/

gerard4143 371 Nearly a Posting Maven

This question is asked so many times that a sticky should be made. Check out this link:

https://www.securecoding.cert.org/confluence/display/cplusplus/EXP34-C.+Do+not+depend+on+order+of+evaluation+between+sequence+points

Plus I'm not sure if this is a typo or not

a++ + b++ + ++b + ++ a + a++

You have a space between ++ a....Its just harder to read your intentions

gerard4143 371 Nearly a Posting Maven

I need the coding for the following question in C:
Read and print all the consonants from a file (no duplicates). Assume the file is a .txt file. The consonants are then to be sorted in alphabetical order.

Again, read this

http://www.daniweb.com/forums/announcement118-2.html

gerard4143 371 Nearly a Posting Maven

We provide help, or answers to specific questions..So what have you tried so far? What is your specific question?

gerard4143 371 Nearly a Posting Maven

On a unix server (ssh), the void pointer is 8 bytes while the unsigned int is 4.

On my IDE (dev-c++), they are both 4.

So am I truncating 4 of the bytes when I typecast it?
How to I avoid doing so? Should I change their type to begin with? What to?

Try unsigned long

sizeof(void*);
sizeof(unsigned long);

gerard4143 371 Nearly a Posting Maven

Is there a method in Linux to monitor a port for activity, then when found, execute a script?

For example, when tftp port 69 is accessed, run a script that runs commands?

thank you.

I'm going to say no but any ftp program should have the ability to log any access.

gerard4143 371 Nearly a Posting Maven

try printing out the sizeof(void*)
and the sizeof(unsigned int);

Are the values the same?

gerard4143 371 Nearly a Posting Maven

wc - word count with the -l option count the number of newlines

This is right from man wc

-l'
`--lines'
Print only the newline counts.

gerard4143 371 Nearly a Posting Maven

hi there i have an assignment about writing Cshell with some features i m not gonna ask plz gimme the codes or smth. but i need some advice how to start writing it, what to do maybe smn can show me ways to do it , thanks for help

here is the assignment :

here are the minimum requirements of the shell you are required to write.
1. It should be able to run all the single-process commands.
2. It should be able to run all the two-process pipelines, the skeleton of which is as given in Fig. 1–13 of the
text.
3. It should be able to handle input and output redirection.
4. It should be able to execute commands in the background.
You are, of course, free to add more features to the shell you write.

This isn't a homework completion forum. We help people who show an effort and have specific problems...Please see this link

http://www.daniweb.com/forums/announcement118-2.html

gerard4143 371 Nearly a Posting Maven

I would check the number of } braces you have in your function definition.

Also calling a function print is probably a bad idea, considering you already have fprintf, printf, sprintf, vprintf, ... defined in the standard library.

Why these lines?

#include <iostream>

using namespace std;
gerard4143 371 Nearly a Posting Maven

You really should check the results of this action

fp=fopen(argv[i], "r");

Something like

if (!(fp=fopen(argv[i], "r")))
{
	fprintf(stdout, "could not open %s\n", argv[i]);
	exit(EXIT_FAILURE);
}
gerard4143 371 Nearly a Posting Maven

I am not sure what this means and I get it all the time.

Really and what would that be?

Can someone help me fix this code?

What's wrong with it beside not having code tags?

gerard4143 371 Nearly a Posting Maven

The forums purpose is to provide assistance not complete solutions...Please post what you have completed so far and any detailed questions.

As for the meaning...

Since I'm not in your class I can only speculate about the absolute meaning of the question...

To me it seems you have to open a text file and read each line of input and display it without any trailing blanks or tabs and skip blank lines but like I said I'm not in your class so this is only speculation.

gerard4143 371 Nearly a Posting Maven

but its not working as i expected.

What were you expecting...my crystal ball's on the fritz and the Amazing kreskin is busy right now..

jephthah commented: i'm always partial to sarcasm. ;) +6
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

Could you give use an example of what the filename looks like after its been modified.

gerard4143 371 Nearly a Posting Maven

Thanks! That makes it a little easier. So the syntax is basically just the construction of the assembly code, although the code is the same? But if there are two identical computers with the same hardware and microprocessor, is there portable code that can be applied to both OS's and still function properly?

If you don't require any operating system services then 'maybe' yes. This discussion doesn't take into account all the emulators that are available out there to simulate different environments.