Author Topic: C programming for BASIC programmers  (Read 1074 times)

jbk

  • Full Member
  • ***
  • Posts: 226
    • View Profile
C programming for BASIC programmers
« on: November 19, 2023, 04:55:08 PM »
trying to learn a bit of C, I find string handling a pain
string parsing, splicing and dicing was problematic in BASIC but it's a lot more difficult in C for a novice like me
anyone knows where I can find public domain C string routines that you find in basic?

Robert

  • Hero Member
  • *****
  • Posts: 1206
    • View Profile
Re: C programming for BASIC programmers
« Reply #1 on: November 19, 2023, 06:05:49 PM »
trying to learn a bit of C, I find string handling a pain
string parsing, splicing and dicing was problematic in BASIC but it's a lot more difficult in C for a novice like me
anyone knows where I can find public domain C string routines that you find in basic?

https://en.cppreference.com/w/c/string/byte

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2104
    • View Profile
Re: C programming for BASIC programmers
« Reply #2 on: November 19, 2023, 07:05:09 PM »
C string routines that you find in basic?

The answer is right under your nose.  Use BCX.

Translate this then look at the source code that BCX emits.  (Start at the bottom and move up)

DIM A$
A$ = "Hello, World!"
A$ = UCASE$(A$)
PRINT A$

Repeat for all other BASIC string functions that you're interested in.



jbk

  • Full Member
  • ***
  • Posts: 226
    • View Profile
Re: C programming for BASIC programmers
« Reply #3 on: November 19, 2023, 07:37:02 PM »
thanks Robert & MrBcx  :)
Robert I already had the C/C++ references bookmarked
MrBcx I have looked at the code produced by BCX but I don't feel that I have the right to use your code in source form, especially if I want to share it to the public
also, even though I find it hard to get comfortable with C strings, it's good for me to learn it's use
basically, I am porting my MP arithmetic to C but the string to MP conversion and vice versa are giving me a tough time, but I am almost there  ;D

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2104
    • View Profile
Re: C programming for BASIC programmers
« Reply #4 on: November 19, 2023, 08:05:22 PM »
MrBcx I have looked at the code produced by BCX but I don't feel that I have the
right to use your code in source form, especially if I want to share it to the public
JB - The MIT License at the top of BC.Bas explains your right to do so.

'******************************************************************************
'                     BCX - The Basic To C/C++ Translator
'               Copyright 1999 Kevin Diggins (All Rights Reserved)
'              Significant contributors to the BCX project include:
'  (Devs)  Robert Wishlaw, Mike Henning, Wayne Halsdorf(RIP), Ljubisa Knezevic
' (Hosting)       Jeff Shollenberger, Fernando Ortiz(RIP), Dave Navarro
'******************************************************************************
'      BCX is distributed under the general conditions of the MIT License.
'                https://en.wikipedia.org/wiki/MIT_License
'                                MIT License
'******************************************************************************
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:

'
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.

'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
' OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
' IN THE SOFTWARE.

jbk

  • Full Member
  • ***
  • Posts: 226
    • View Profile
Re: C programming for BASIC programmers
« Reply #5 on: November 21, 2023, 05:42:33 PM »
I think that I finally have the I/O routines to my satisfaction, one thing I find very useful  is MS Visual Studio source code parsing, it gives helpful warning, though VS is not perfect, one time I forgot a closing quote in a string literal and it freaked out
I use VS to check my code but gcc produces much faster exes  :)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2104
    • View Profile
Re: C programming for BASIC programmers
« Reply #6 on: November 21, 2023, 08:04:47 PM »
I think that I finally have the I/O routines to my satisfaction ...

Anything new worth sharing for the curious types reading this thread?


jbk

  • Full Member
  • ***
  • Posts: 226
    • View Profile
Re: C programming for BASIC programmers
« Reply #7 on: November 22, 2023, 03:30:22 AM »
MrBcx, I only wanted to share my delight in the impressive code analysis of VS, any of my simple code would not be interesting to anyone, it might even invoke disgust  ;D