LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-25-2010, 11:59 AM   #1
nerovin
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Rep: Reputation: 0
Unhappy Bar code reader


HI!

I have a assignment relating to barcode reading.Let say i have to enter the 13 digit barcode with hyphen e.g "Enter barcode:123-46574-48847" using scanf.Once thats done how do i extract the values without the hyphen
e.g using printf "1234657448847". No arrays No strings and No function is allowed.
No while loop is allowed

The lecturer's tip was to treat "-" as negative and not hyphen.

So how do i go about in solving this problem?.
 
Old 03-25-2010, 12:44 PM   #2
Maligree
Member
 
Registered: Mar 2008
Distribution: Gentoo, CentOS, Fedora, Arch
Posts: 231
Blog Entries: 1

Rep: Reputation: 42
Bleh, homework.

Not sure I understood, though. Would this piece of code be of any help to you?
Code:
#include <stdio.h>

int main(int argc,char **argv) {

    char str[]="123-46574-48847";
    int a,b,c,d,e,f;

    sscanf(str,"%d-%d-%d",&a,&b,&c);
    sscanf(str,"%d%d%d",&d,&e,&f);
    printf("%d %d %d\n",a,b,c);
    printf("%d %d %d\n",d,e,f);

    return 0;
}
 
Old 03-25-2010, 12:59 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Per the LQ Rules, Do not expect LQ members to do your homework - you will learn much more by doing it yourself.. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

I have asked that this thread be moved to a more appropriate forum.
 
Old 03-25-2010, 06:37 PM   #4
nerovin
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Original Poster
Rep: Reputation: 0
As to this question i actually did 3/4 of my work. i just need the last piece to solve my problem.Let me explain what i did so far sudo code

int main(int argc, char*argv[])
{
long long bar;
printf("Enter the barcode:");
scanf("%lld", &bar);

printf("Barcode is %03lld-%06lld-%03lld-%01lld\n",
bar(first3digit),(BAR2(the next5digit),Bar3(The next3 digit),Bar4(the last digit));

This program scans the 12digit number and once that done what i did was to separate the 12 digit number accordingly to the barcode e.g 123456789012 to 123-45678-901-2

its all good from here. The problem i'm facing is that now someone input numbers and hyphens into my program
e.g 123-45678-901-2 how do i convert it back to 123456879012 with without char str,no strings,no arrays,nofunction. Just by using scanf to convert it back
 
Old 03-25-2010, 07:11 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by nerovin View Post
As to this question i actually did 3/4 of my work. i just need the last piece to solve my problem.Let me explain what i did so far sudo code

int main(int argc, char*argv[])
{
long long bar;
printf("Enter the barcode:");
scanf("%lld", &bar);

printf("Barcode is %03lld-%06lld-%03lld-%01lld\n",
bar(first3digit),(BAR2(the next5digit),Bar3(The next3 digit),Bar4(the last digit));

This program scans the 12digit number and once that done what i did was to separate the 12 digit number accordingly to the barcode e.g 123456789012 to 123-45678-901-2

its all good from here. The problem i'm facing is that now someone input numbers and hyphens into my program
e.g 123-45678-901-2 how do i convert it back to 123456879012 with without char str,no strings,no arrays,nofunction. Just by using scanf to convert it back
Why not 'printf' to convert it back to number ?
 
  


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
Bar code scanning with a portable data terminal? brucerowe Linux - Hardware 5 01-22-2009 01:58 AM
Bar Code Reader Device Driver Development Ulises Linux - Kernel 2 01-24-2007 09:02 AM
Laser Bar Code Scanner alex2k4 Linux - Hardware 2 10-08-2005 02:06 PM
USB Bar Code Scanner... How To!?? FreakboY Mandriva 0 05-06-2004 02:30 AM
Sample code to build a window with slider bar? NewComer Programming 3 02-12-2004 01:34 PM

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

All times are GMT -5. The time now is 07:11 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