Aia 1,977 Nearly a Posting Maven

sanushks> Thanks! atoi works...
Do you know what happens if atoi fails to convert?
Your first choice of using sprintf was superior, since error checking is better with it.

Aia 1,977 Nearly a Posting Maven

serkan sendur> you live in USA-welfare country.
It used to be called The Land of Opportunity.
Now, it is more like the camel in the desert, that must survive out of whatever is in the hump. Hoping that water is found before it dries out.


serkan sendur> -i have been living in USA for the last 7 months. so i have different perspective to see things over here.
Don't worry, you'll be assimilated soon enough.

Aia 1,977 Nearly a Posting Maven

John A> I dunno, 30,000 songs
Whoa! Quite an investment.

Thirteen songs in my Library. I am very picky choosing music.
Nevertheless, I have a growing collection of audio books.

Aia 1,977 Nearly a Posting Maven

lolguy> the removing of the character outside it whish should increment the j to 3 whish should remove E

You are confused. printf("%d",j); is not the subscript used to delete the matched character. for (i = j = 0; s[i] != '\0'; i++) means, walk through the string until you find the string terminator if (s[i] != c) as we walk through the string, if the present char s doesn't match the given character to be deleted, then and only then s[j] = s[i]; which keeps track of the all new and improved string. After that the work jump to the next char by j++; s[j] = '\0'; makes sure that in case the loop finished with the original string, the new one is properly terminated and therefore a valid string as well.

jephthah commented: break it down! +9
Aia 1,977 Nearly a Posting Maven

serkan> and i wont feel like foreigner each time i am asked what my name is. it always reminds me that i am a foreigner and causes some sort of alienation.

In a more sober note, I hate to tell you this. It will never happen.
As soon as you open your mouth, people will remind you that you are a foreigner. At times it will not be necessary for you to say anything.
You are an immigrant and even if your name is Elvis Presley, you are a foreigner. Nothing wrong with it.

There are reasons to change your "legal name", but so far what you have say don't seem to be good reasons.
To honor the name your mother gave you should be a meaningful power behind against changing it.

And Serkan is a good name, even if anyone could not pronounced like it should be pronounced.

Nevertheless, even the name Julian (belonging to Julius) came to be because people couldn't pronounce the original one.

I'll say, make a name for yourself and always remind them how to pronounce it.

Aia 1,977 Nearly a Posting Maven

I think a name change would be a great idea :) John Doe or Bill Smith would be a good names to inherit.

Anything but Joe Dick

Aia 1,977 Nearly a Posting Maven

>Apparently the return value from gets() differs in some way from the return value of fgets() -- enough to break the code as I've written it.

fgets() reads and include the enter key to the string, you need to remove it.
Maybe something like:

if ( fgets(filename, sizeof filename, stdin) )
{
    len = strlen(filename) -1; /* position before '\0' */
    /* if it's a new line remove it */
    if ( filename[len] == '\n')
        filename[len] = '\0';
}

gets() doesn't include the new line.

Forget that gets() exists.

Aia 1,977 Nearly a Posting Maven

try sed "s/$jobname//1" this will only remove the dirst substitution

I am afraid that command doesn't produce the advertised result.

Aia 1,977 Nearly a Posting Maven

I think there the prototypes of the function setting the return type and name.

As well as the parameters that it would take if it takes any. Allowing the compiler to check that the function is properly defined.

Let's look at this function prototype then.

int display(int i);

returns an integer and accept an integer.

What do we have defined?

int display(int i)
{
    printf("%s\n" , list[i].name);
    printf("%s\n" , list[i].street);
    printf("%s\n" , list[i].town);
    printf("%s\n" , list[i].county);
    printf("%s\n" , list[i].code);
/* missing the int return */
}

It declares the proper integer return but in the body of the function nothing is returned.
Nevertheless, in actuality it doesn't need to return anything. Making possible for us to change the definition as this.

void display(int i)
{
    printf("%s\n" , list[i].name);
    printf("%s\n" , list[i].street);
    printf("%s\n" , list[i].town);
    printf("%s\n" , list[i].county);
    printf("%s\n" , list[i].code);
}

And then the prototype so the compiler doesn't complain.

void display(int i);

Now, you have many of those. Go and make the changes.
By the way, it is not a good idea to mix C syntax with C++. This code is mostly C syntax in a C++ template.

Aia 1,977 Nearly a Posting Maven

OP> But when i do it gives me errors on most of my functions saying they 'must return a value', when i void the functions

Do you know what these are at the beginning of the program?

void enter(), save(), load();
int del(), search(), show_list(), find_free();
int menu_select(), find(char *name), display(int i), init_list(), inputs(char *prompt , char *s , int count);
Aia 1,977 Nearly a Posting Maven

Thanks guys, its working. ur gods of the internets.

Phil

GREAT eBAYER»-(¯`v´¯)-»YOU ‹(•¿•)› POSITIVE w/ 5*-:¦:-THANX-COMEBACK.A++++++++++

[Edit] Oops! Wrong internet.

Aia 1,977 Nearly a Posting Maven

You know at least this is not C but rather C++, right?

OP> the main errors are in with "for(i=0; i&lt;MAX; i++)" this part of the code but i can't see whats wrong. for ( i = 0; i < MAX; i++) is the correct syntax.

Aia 1,977 Nearly a Posting Maven

>Anyway, one more favor, care to explain
It would require a base understanding that would take some time to write. Fortunately, others has done it already. Take a look at this link, and pay attention to commands and grouping with {}.
The sed FAQ has a lot of valuable information as well.

Aia 1,977 Nearly a Posting Maven

>sunny╠╠╠╠╠╠╠
>do you know why this is?
Most likely because no null terminator '\0' is finishing the string.

Aia 1,977 Nearly a Posting Maven

>le sigh.
:D

It seems you've suffered enough for that bit of code, so I'll restrain myself.

Must you? Could we encourage you to change your mind? For the good of the community, please? :D

jephthah, don't worry I'll try to bandage you up afterward. :P

Aia 1,977 Nearly a Posting Maven

This is old school indeed:

Yes, before my time with the language. And even when I am aware of the difference in defining the function in the old way, I completely missed.

Aia 1,977 Nearly a Posting Maven

>Any ideas?
That source code is making an easy job extra complicated.
All that is needed.

char *dress_down(char *s)
{
	while (*s) {
		*s = tolower(*s);
		++s;
	}
	return s;
}

Assuming a non-read-only string named text.
You'll call it, and it will convert only the characters that has an equivalent in lower case.

printf("%s\n", dress_down(text));
Aia 1,977 Nearly a Posting Maven

This source code is plagued with syntax errors. printf ("word: <%s>\n", w); requires the header file stdio.h

int set_keysig (type s, type ks, type init);

Prototype missing ; and type, where type is any data type like int, float, structure, pointer, etc. char s[x]; length of string needs to be declared.

John A commented: I'll give you a cookie for trying. But sorry, it's completely valid C89; that's just an old form of a function definition. :P +18
Aia 1,977 Nearly a Posting Maven

>And your correction as the italicized exception, product of bad practice.
While you're entitled to your own opinion, that statement is just BS.
[...]

In the interest of not entering a pissing contest I am going to leave it at that.

Aia 1,977 Nearly a Posting Maven

>Prototypes don't go inside other functions.
Wrong. Prototypes don't usually go inside other functions.

While placing prototypes at the beginning of the program, and outside any function, is not strictly necessary, it is a measurement of good practice. Therefore I support the statement of MosaicFuneral as
correct, in the spirit of good practice. And your correction as the italicized exception, product of bad practice.

Aia 1,977 Nearly a Posting Maven

#include<stdio.h>
#include<math.h>
int main(main)
{
printf("\n%d",main+=pow(++main,++main));
return 0;
}

>what does the above program do with "main"?

A mockery of the C Standard, and a massive example of undefined behavior.

Aia 1,977 Nearly a Posting Maven

>But, I'll still look for that [one-liner].
Because originally you used the switch -i I assumed your version of sed was GNU.
Thus sed -ie "0,/$JOBNAMES/{//d;}" filename should have work.
However, if you are not using GNU sed this rather more involved syntax will delete the first occurrence of a regex.

sed '/'"$JOBNAMES"'/{x;/Y/!{s/^/Y/;h;d;};x;}' JOBLIST.txt

Watch the quotes scheme (')(")$JOBNAMES(")(')

Aia 1,977 Nearly a Posting Maven

Instead of :

sed -ie "\|^$JOBNAME\$|d"

try:

sed -ie "0,/$JOBNAMES/{//d;}" filename

The workhorse bit is "0,/RE/". It looks from starting line until first occurrence of REGEX

>I really am a newbie to scripting but working hard to learn the way of the force.
Here's the tools to construct your "light saber," young Jedi.

Aia 1,977 Nearly a Posting Maven

Any argument passed in the command line is going to be a string as you seems to know. However, casting it to just an int is not going to help. You need to convert that string numeric representation into an integer.

You could parse it using sscanf() or maybe convert using strtol()

Aia 1,977 Nearly a Posting Maven

I don't know what the function gtk_button_new_with_label() does since it is not prototyped in the code you provide, however, it appears that returns a pointer and not an int.
Making all the errors part of the same problem.

vass.c:80: warning: assignment makes integer from pointer without a cast

That's the first error warning and it is saying: Hey, I am returning a pointer and you are trying to push it into an int called buttons_add_audio_input[i]

vass.c:81: warning: passing argument 1 of ‘gtk_widget_set_size_request’ makes pointer from integer without a cast

Second error warning: Hello, I am gtk_widget_set_size_request() function and I don't take an integer as my first argument. Guess what's the first argument? Yeap, buttoms_add_audio_input[i] integer that it was
wrong before.

vass.c:82: warning: passing argument 2 of ‘gtk_fixed_put’ makes pointer from integer without a cast
vass.c:83: warning: passing argument 1 of ‘g_signal_connect_data’ makes pointer from integer without a cast

Well, to end this parade of complainers, let's look at these two together.
Since you keep bouncing around that int buttons_add_audio_input[i] gtk_fixed_put and g_signal_connect_data functions don't want to feel like children of a lesser god and of course they complained when you tried to shovel that int in their throats, since they only like pointers and are prejudiced against ints.

Does it help?

Aia 1,977 Nearly a Posting Maven

>while(!feof(file))

I glanced very quickly to your last post and saw that.
feof(file) would never give you the expected result as a loop control.
See here for some explanation.

Furthermore that for loop will continue regardless if fscanf() can read a conversion or not. It should be able to stop when fscanf() fails.

Aia 1,977 Nearly a Posting Maven
Aia 1,977 Nearly a Posting Maven

If I understand you correctly, you want to create variables dynamically at run time.

No. It is not possible.
C is strongly typed. Variables need to be declared before hand.

Aia 1,977 Nearly a Posting Maven

>And my earlier query of why

#define int float

>is still not clear...

You are substituting in your code, every word int for the word float.
That's all.
So, what happens when for example you write?

float main(void)

It doesn't work properly, correct? Because main should return an int.

Aia 1,977 Nearly a Posting Maven

>Writing programs for chess is too difficult and such complex calculations can be done practicallly only by supercomputers

Darn! I knew that my Sony CLIE pda was a powerful machine, but I had no idea of its true supercomputer nature. ;)

Aia 1,977 Nearly a Posting Maven

>any ideas?
I am not running any version of Solaris so I don't know what's the "gotcha."
But if sprintf() is doing the job after the suffix "GB" is erased, let's do it.
Make an awk file that contains this:

#!/usr/bin/awk -f

$3 ~ /s/ {
    if ( index($2, "GB") ) {
        split($2, dissect, "G");
        $2 = sprintf("%8.2f", (dissect[1]*1024));
    }
    else {
        split($2, dissect, "M");
        $2 = sprintf("%8.2f", dissect[1]);
    }
    print $0
}

Then, call it with the input file

awk -f convert.awk data > outputdata

Where convert.awk is this awk file we talked about previously, data is the output to analyzed, and outputdata is the result file.
Note: check that awk lives in the /usr/bin/awk. If not, change in awk file accordingly. Usually the command which awk will tell you.

Aia 1,977 Nearly a Posting Maven

While that could work as an exercise for logic, there's already a couple of standard I/O functions that will help you to know the size of a file in a generic way, in the absence of more efficient API.

long aia_gfs(FILE *file_handle)
{
	/* file pointers */
	long current_position, end_position;

	if (file_handle != NULL) {
		/* obtain current file pointer position */
		current_position = ftell(file_handle);

		/* 
		 * seek to the end of file 
		 * SEEK_SET is start of file
		 * SEEK_END is end of file
		 */
		fseek(file_handle, SEEK_SET, SEEK_END);

		/* obtain end file pointer position */
		end_position = ftell(file_handle);

		/* restore file pointer to beginning of file */
		fseek(file_handle, current_position, SEEK_SET);

		/* divulge size of file */
		return end_position;
	} else {
		fprintf(stderr, "Couldn't read file");
		return -1;
	}
}
Aia 1,977 Nearly a Posting Maven

Ohhh I see my mistake now -- wasn't the parantheses, but the fgets() function instead of fgetc(). Thank you for the correction. :)

Just a tiny typo but I felt to bring it up to the attention of the OP. :)

Aia 1,977 Nearly a Posting Maven

Nope. You have mis-matched parentheses. Count them.

Yes, I erased a parentheses when fixing the color manually.
It should be: while((c = fgetc(fp)) != EOF) >1) c must be of type int, not char, because EOF won't fit in a char.

It will fit a char, but there's not guarantee that it would be a signed char that can hold negatives. Furthermore, that's what fgetc() returns, an int, therefore, that's what it should be.

Ancient Dragon commented: you are right :) +36
Aia 1,977 Nearly a Posting Maven
int spot = 0;
int c;
while( (c = fgets(fp) ) != EOF)
{
    string[spot++] = c;
}
string[spot] = 0; // null-terminate the string

He really meant while((c = fgetc(fp) != EOF) And some further information. You really need to pass it a limit of how much it can read into the string, if not there's the possibility of over flowing.
The file closing needs to be inside the if() right after the string[spot] = 0; // null-terminate the string That's where it makes sense, since as it stands it will execute even if it could not open it.

Aia 1,977 Nearly a Posting Maven

Is your keyboard broken? It looks like sticky key with (!), (,) and (?).
Do you know that ALL caps represents YELLING! Not cool! Stop yelling at people you don't even know.

Learn how to use a loop, and include the scanf() inside one.

Aia 1,977 Nearly a Posting Maven

>So sprint if getting the values however they still have either MB or GB on the end so therefore the sprintf statement wouldnt work would it?

Yes, it would. sprintf() tries to read and convert any string to the format you give it.
To convince you run

echo "1.2GB" | awk '{print sprintf("$8.2f", $1)}'

...and watch the result.

Aia 1,977 Nearly a Posting Maven

Hi,
Im using solaris 10 and the script is running with KSH could this be causing it?

You get that result because sprintf is not receiving any value in column $2 that can convert into a decimal.
For debugging purposes substitute every line with a sprintf() call for just a print of $2 to see the result.

You could also post your script and help us to help you.

Aia 1,977 Nearly a Posting Maven

Assuming data format:

d15 509MB c1t0d0s5
d13 7.0GB c1t0d0s3
d11 1.5GB c1t0d0s1
d10 10GB c1t0d0s0
d25 509MB c1t1d0s5
d23 7.0GB c1t1d0s3
d21 1.5GB c1t1d0s1
d20 10GB c1t1d0s0

For example purposes coming from datafile to awk and displaying to standard output. Modify to need.

awk '/s/ {
        if ( index($2, "GB") ) {
            $2 = sprintf("%10.2f", ($2*1024))
        }
        else {
            $2 = sprintf("%10.2f", $2)
        }
        print $0 
}' datafile

No need of calling grep to pipe only lines containing an s at column $3

/* output example
d15     509.00 c1t0d0s5
d13    7168.00 c1t0d0s3
d11    1536.00 c1t0d0s1
d10   10240.00 c1t0d0s0
d25     509.00 c1t1d0s5
d23    7168.00 c1t1d0s3
d21    1536.00 c1t1d0s1
d20   10240.00 c1t1d0s0
*/
Comatose commented: Genius! Well Done. +12
Aia 1,977 Nearly a Posting Maven

Try this and see if you can figure out:

echo "2.3 4.56789" | awk '{printf "%.2f %.2f\n", $1, $2}'
Aia 1,977 Nearly a Posting Maven

>What does the e+11 and e+10 mean??
Search for scientific notation. When a number is large in length (very big or very small), a method has been invented to represent it using exponent.

Aia 1,977 Nearly a Posting Maven

There is a great deal of truth in that video. I have dish network tv with over 100 channels to choose from, and there are days when there isn't a thing that I want to watch.

The remainder deal of falsehood must be compelling enough for you to not cancel your subscription.

Aia 1,977 Nearly a Posting Maven

> I also changed "\n" to '\n' and my comparison operator to !=.
That's a sensitive thing to do, since "\n" is a string made of '\n' and '\0'.

Aia 1,977 Nearly a Posting Maven

>Since fgets() deals with files and my program only uses stdin
stdin is an open file. scanf( "%s", str); can and should be substituted by fgets(str, sizeof str, stdin); >gets() should work fine
NO. forget that gets() exists. You can take my word for it, or you can go the long road, and search this site for a `why'.

Aia 1,977 Nearly a Posting Maven

scanf( "%s", str); will never include the newline into the string `str'. scanf() is designed in its default form to stop reading when it finds a space or newline.

Bottom line. scanf() is a poor choice to read input string from stdin.
fgets() is a favorite of many.

Aia 1,977 Nearly a Posting Maven

>(I think I'm over running an array but can't see where).

table[15][1] = 0;

To start, table can only be indexed to 14

>(anything at all!)
There's not guarantee that malloc will allocate memory. You MUST check the return of that call.
Where do you free the malloc()ed memory that you set apart?

Aia 1,977 Nearly a Posting Maven

John, Manager, Finance, $2000
Jack, Accountant, Finance, $1500

If you take off the $ sign from the field value it might work.

[Edit] Don't disregard Salem's advice. You're lucky I didn't noticed it before. I usually don't entertain posts from people that willingly ignores the forums conduct.

Aia 1,977 Nearly a Posting Maven

Wave.h:

#ifndef WAVE_H
#define WAVE_H

typedef struct
{
	unsigned short formatTag;
	unsigned short numChannels;
	unsigned int samplesPerSec;
	unsigned int bytesPerSec;
	unsigned short blockAlign;
} WAVE_INFO;
typedef struct
{
	WAVE_INFO *info;
	SAMPLE *data;
} WAVE_FILE;

bool getWaveData(WAVE_FILE *file, char *filename)
{
	// function body, not important
}

void extractWaveFrames(FRAME *frames, WAVE_FILE *file, unsigned int startFrame, unsigned int endFrame)
{
	// function body, not important
}

#endif

Prepocessor directives (including #include, macros); structures, enum and typedef; global (and extern) variable declarations; function prototypes; comments; are alright to write onto a header file, but it should not include source code that will cause machine code to be generated.

Aia 1,977 Nearly a Posting Maven

Impossibility is playing a role in your distress. You could not have been born in two different months, nor could you have been born in a day that is earlier and later that a significant period, at the same time.

There's an order of precedent as well to take in consideration. Use () with && and || operators.

Aia 1,977 Nearly a Posting Maven

I understand ksh-93 does support float but it is not an option to use this. How would I do it with bc, calc, awk or perl?

result=$(echo $var1 $var2 | awk '{print $1 - $2}')

$1 inside awk becomes whatever variable you past first, and $2 becomes the second variable and so on.
More about awk
bc examples

chris5126 commented: thanks the help much apreciated! +3