LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2003, 04:00 PM   #1
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Can you compare function return's in a 'while' loop?


Hi! I wonder if i can compare two(if two then i can do more) function return's
in a while loop. Example:
Code:
while (!(scanf("%s", password) && (strcpy(password, crypt(password, salt)) 
	{				   
		if (strcmp(password, read) < 0 || strcmp(password, read) > 0)
		{
			hold(2);
			printf("\nPassword incorrect\n");
			printf("Password:");
	        }
        }
kev82 i know your in the forum now, if you see this don't mind the 'scanf()', i'll be getting rid of it. i must find out if i can do this, if i can...COOL! The above won't compile, but instead give's me a large cascade of error's, which has to be the while loop above, i don't want to see corrected code, but instead would just like to know if i can do it.
Thank's for any reply's.
 
Old 08-04-2003, 04:05 PM   #2
Stuka
LQ Newbie
 
Registered: Feb 2003
Location: Houston, TX
Distribution: Debian/RedHat/Slack
Posts: 12

Rep: Reputation: 0
That's definitely doable - what kind of errors is it giving you?
 
Old 08-04-2003, 04:11 PM   #3
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Original Poster
Rep: Reputation: 30
Error's i can't list because i can't copy the info from konsole in KDE, buuuut
that's all the info i needed anyway, COOOOOOL, and thank's.
{Edit}
Here's the error's.
Code:
[Mirrus][karensmith][04:22:08[/Source][$] gcc login3.c -lcrypt -o /Exec/login3
login3.c: In function `main':
login3.c:53: parse error before `{'
login3.c:55: parse error before `{'
login3.c: At top level:
login3.c:60: parse error before `}'
login3.c:61: parse error before `2'
login3.c:61: conflicting types for `hold'
login3.c:27: previous declaration of `hold'
login3.c:61: warning: data definition has no type or storage class
login3.c:62: parse error before string constant
login3.c:66: warning: parameter names (without types) in function declaration
login3.c:66: conflicting types for `free'
/usr/include/stdlib.h:538: previous declaration of `free'
login3.c:66: warning: data definition has no type or storage class
login3.c:67: parse error before `-'
login3.c:67: conflicting types for `exit'
/usr/include/stdlib.h:577: previous declaration of `exit'
login3.c:67: warning: data definition has no type or storage class
login3.c:69: warning: parameter names (without types) in function declaration
login3.c:69: warning: data definition has no type or storage class
login3.c:70: parse error before `return'
[Mirrus][karensmith][04:22:38[/Source][$]
They don't make sense, i've seen reaction's like this before when doing some funky if statement's, but the rest of the code is solid, i believe it's the while loop. Thank's.

Last edited by Tarts; 08-04-2003 at 04:31 PM.
 
Old 08-04-2003, 04:30 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
Quote:
kev82 i know your in the forum now, if you see this don't mind the 'scanf()', i'll be getting rid of it.
LOL, anything that helps you learn is very good i was only talking about a final product in the other thread.

the error appears to be a missing ) on the line with the while on it, or rather an extra ( before the strcpy. vim and emacs bracket matching is a wonderful thing.

Last edited by kev82; 08-04-2003 at 04:35 PM.
 
Old 08-04-2003, 04:39 PM   #5
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by kev82
LOL, anything that helps you learn is very good i was only talking about a final product in the other thread.
Hehe, I must admit my mind can't grasp the thought of a final product in this point in time.
Quote:
the error appears to be a missing ) on the line with the while on it. vim and emacs bracket matching is a wonderful thing.
Ok so there's a solid reason to use vim, 'man vim' i go. Thank's everyone.
 
Old 08-05-2003, 06:16 PM   #6
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Original Poster
Rep: Reputation: 30
kev82, i saw you where in here (lucky for me){edit}(you dissapeared), i can't seem to find the command for bracket matching for vim in ':help', i read the ':help usr_06.txt'
for syntax highlighting, do you just edit the syntax highlighting (?) because i tryed the command ':syntax enable' and the parenthesis where not color coded the way i figured, is that what you mean be bracket matching, color coding?
Thank's for any reply's!

Last edited by Tarts; 08-05-2003 at 06:20 PM.
 
Old 08-05-2003, 06:56 PM   #7
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
theres no internal vim command to bracket match as far as i know but theres a plugin for it somewhere here: http://users.erols.com/astronaut/vim/index.html

i need to go to sleep - what i meant to say was, if you go over a bracket and press % it will show you the matching bracket, the above should be nicer though.

Last edited by kev82; 08-05-2003 at 07:13 PM.
 
Old 08-05-2003, 07:03 PM   #8
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Original Poster
Rep: Reputation: 30
Thank's for the link! I'll check it out!

{edit}
I don't want to keep you up , but is this plugin for 'visual' mode, if it is it's pretty usless to me, i'd rather be able to use 'vim' not in x.
I hope you read this i didn't want to reply to this thread again.
Let me try % in 'vim' out of x and see what happen's.
Thank's.

Last edited by Tarts; 08-05-2003 at 07:34 PM.
 
Old 08-05-2003, 07:36 PM   #9
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
visual mode is a mode in vim for selecting text and has nothing to do with X it is activated by pressing v in command mode.

the plugin is designed to be used in command mode(where you press x to delete, i to insert, etc) by enabling the plugin \[i as you move over a bracket vim will highlight its matching bracket. the plugin can be disabled by \[s
 
Old 08-05-2003, 07:50 PM   #10
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Original Poster
Rep: Reputation: 30
Got it. Thank's!
 
Old 08-06-2003, 12:41 AM   #11
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
With vi/vim, you can also, in escape mode, use the % key to find the matching bracket of the one your cursor is sittling on.
 
Old 08-06-2003, 07:24 PM   #12
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Original Poster
Rep: Reputation: 30
Vim rock's, for without it i couldn't do somthing:
Code:
while ((!(scanf("%s", password))) || (strcpy(password, crypt(password, salt)) != read) && (strcmp(password, read) != 0))
	{					           
		if (strcmp(password, read) != 0)
		{
			hold(2);
			printf("\nPassword incorrect\n");
			printf("Password:");
		}
        }
	hold(2);
like that. :) :) :)
kev82 unfortunatly i could'nt get the plugin working, i moved into '/usr/share/vim/vim61/plugin' directory, then tryed enabling it with '\[i'
all i got was 'scanf()' declaration at the bottom, which i couldn't tell was a vim feature, or the plugin? But thank's for everything kev82, and all other's.
{edit} '\[i' with or without the plugin show's the function declaration of the function the cursor is sitting on, still cool though.

Last edited by Tarts; 08-06-2003 at 08:13 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling another function from a function using GTK geminigal Programming 4 07-11-2005 03:15 PM
what are the Hexadecimal function and ASCII function in Perl Bassam Programming 1 06-03-2004 01:44 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Is the wait function is the same as the sleep function ? Linh Programming 3 04-28-2004 12:39 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration