Quick explanation on String manipulation tutorial

Hello and Happy new year to all members of this community

I'm still trying to learn how to manipulate string using array and buffer. The end goal is to construct an URL that will send data to trough PushingBox to a Google Sheet

I came across a tutorial: C - Strings See the code below

My childish and un-experience question.

How do I get the result be printed using the Serial.print function on the COM3 page.
Serial.printf is not accepted by the compiler

Any help, tutorial link, library or explanation about using array of char[] to create a URL string? I'm stuck with this since too long and I want to learn how to properly use string in the Arduino Uno memory limitations.

My "C++" is very embryonic. I do understand the difference between a string and a char[array] of character to create a string. I need to learn the proper function on library that will let me manipulate strings using the array of characters concept

Martin
Montreal, Canada
P.S. Excuse my English, more fluent in French.

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

int main () {

   char str1[12] = "Hello";
   char str2[12] = "World";
   char str3[12];
   int  len ;

   /* copy str1 into str3 */
   strcpy(str3, str1);
   printf("strcpy( str3, str1) :  %s\n", str3 );

   /* concatenates str1 and str2 */
   strcat( str1, str2);
   printf("strcat( str1, str2):   %s\n", str1 );

   /* total lenghth of str1 after concatenation */
   len = strlen(str1);
   printf("strlen(str1) :  %d\n", len );

   return 0;
}

more fluent in French.

Would you like this topic moved to the French section of the forum ?

Your English is certainly better than my French !

As to your program, did you deliberately not use the normal Arduino setup() and loop() functions ?

A minor point but one that will cause confusion if you don't do it correctly, C style strings (zero terminated arrays of chars) are usually referred to as strings (lowercase s) whilst String objects created using the String library are usually referred to as Strings (uppercase S).

UKHeliBob:
As to your program, did you deliberately not use the normal Arduino setup() and loop() functions ?

A minor point but one that will cause confusion if you don't do it correctly, C style strings (zero terminated arrays of chars) are usually referred to as strings (lowercase s) whilst String objects created using the String library are usually referred to as Strings (uppercase S).

I just copy the code from the tutorial page. So nothing is deliberate... :slight_smile:

I did try to modify the code by including the loop and setup() before asking,

Thanks for the differentiation between "strings" and "String". While I'm still not able to properly work with [stings] I do understand that they are not the same as String.

Martin

I just copy the code from the tutorial page.

Can you please supply a link to the page that you copied the code from ?

Actually I had no problem following you explanation in your first place despite the fact that you mixed the use of string and String but is not always the case

Hello UKHelibob

The link was in my initial post

Martin

There is no Serial.printf on that page

TheMemberFormerlyKnownAsAWOL:
There is no Serial.printf on that page

Hello

I know about that.

Let me reformulate my "dummy "question

How can I see the result of the function main() on the debug screen using a Serial.print ? // see the <main()> code above.

To learn, I need to be able to play around and see a result.

Martin

Are you learning C++ itself or Arduino? The code above is for different environment.

I think some of the ESP platforms have Serial.printf

Sorry I missed that

The problem with copying code from the Web is that it tends to be generic and not designed for the Arduino environment

Try this

void setup()
{
  Serial.begin(115200);
  while(!Serial);
  char str1[12] = "Hello";
  char str2[12] = "World";
  char str3[12];
  int  len ;
  
  /* copy str1 into str3 */
  strcpy(str3, str1);
  Serial.print("strcpy( str3, str1) : ");
  Serial.println(str3);
  
  /* concatenates str1 and str2 */
  strcat( str1, str2);
  Serial.print("strcat( str1, str2) : ");
  Serial.println(str1);
  
  /* total lenghth of str1 after concatenation */
  len = strlen(str1);
  Serial.print("strlen(str1) : ");
  Serial.println(len);
}

void loop()
{
}

UKHeliBob

Thank you, will test that.
Martin