Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:34:58+00:00 2026-05-23T02:34:58+00:00

I know how to program in C# and VB but not have idea about

  • 0

I know how to program in C# and VB but not have idea about how to use C++ and have to program a little exe to a barcode scanner that use C++ 🙁

In this moment I try to parse a scanned barcode that have multiple data sepparated with a “/”, I find that exist a strtok function, tested it “manually” and worked ok but I not implemented yet a working function to call it correctly, what I have now:

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

int elemStr(char *str, char sep)
{
   int cantElem;
   unsigned ich;

   cantElem = 0;

   if (strlen(str) > 0) //at least 1 elem
      cantElem++;

   for (ich = 0; ich < strlen(str); ich++)
   {         
      if (str[ich] == sep)
         cantElem++;      
   }                
   return cantElem;
}

char* getElemStr(char *str, char sep[], int elem)
{   
    char *tempStr = NULL;
    char *tok;                   
    int currElem = 1;

    // 1st data
    strcpy( tempStr, str);
    tok = strtok( tempStr, sep);

    while( currElem != elem )
    {       
        // Get next tokens:
        tok = strtok( NULL, sep );
        currElem++;
    }

    return tok;
}


void main( void )
{
    char barcode[] = "710015733801Z/1/35";

    char sep[] = "/";
    char sep1 = sep[0];

    char barcd[20];
    char piezaChar[4];
    int pieza;
    char mtsChar[4];

    int cantElem;

    cantElem = elemStr(barcode, sep1 );

    if (cantElem >= 1)
    {
        strcpy(barcd, getElemStr(barcode,sep,1) ); //pasa a str resultado;
        printf("Cod: %s\n", barcd ); //STACK OVERFLOW HERE!
    }
 }

if I use strtok witout a function “getElemStr” it work ok but I try to use it on other places too.

Can I use strtok like this? You have a working example?
pd: I not have idea about pointers (sorry), good doc to learn about that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:34:59+00:00Added an answer on May 23, 2026 at 2:34 am

    Here is a C++ solution that doesn’t use boost.

    #include <string>
    #include <sstream>
    #include <iostream>
    
    int main()
    {
        std::string barcode = "710015733801Z/1/35";
    
        std::stringstream ss(barcode);
        std::string elem;
    
        while(std::getline(ss, elem, '/'))
        {
            //do something else meaningful with elem
            std::cout << elem << std::endl;
        }
    
        return 0;
    }
    

    Output:

    710015733801Z
    1
    35
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that being open source does not necessarily makes a program more/less secure
I have a nice program idea, it will be a very simple application that
I know how to program Console application with parameters, example : myProgram.exe param1 param2.
Anyone know how to do this without using a third party program? If there
I know that there're stdout/in/err for a program and I want to redirect a
I know this question looks like a dupe: I checked and it's not In
I have a few projects that are scripted via javascript. Not a web pages,
i have a program(winform) that runs through a lot of files(in the area of
I have a great idea about cheating on exams. My school uses very old
Hey all, I have a question about perl objects and threading. My program is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.