Thread: null terminated strings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2024
    Posts
    6

    null terminated strings

    I'm very new to C.. so please be patient

    I'm trying to read strings that were written to a file by a program written in Visual Basic... which means the strings are not null terminated.

    so what I'm doing is reading the entire file as a single array as 'char ttl[512]' and then using individual loops to copy out the data as needed like this:

    Code:
    for (int i = 0; i < 20; i++) {     
            my_record.art2[i] = ttl[i+129];
           }
     my_record.art2[20]=0;
    and then in the last line inserting the null terminator. the file says Artist 2 is a "string 20 characters long" (in BASIC terms) so I made the artist 2 as "char art2[21]" To allow for the null terminator.

    Is this a valid way of making the strings null-terminated for c to handle? (then I'll reverse the process when I get ready to write the files)

    edit: deleted the rest... I accidentally solved my problem... *shrug*
    Last edited by kc8oye; 01-01-2024 at 05:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. null terminated string lists
    By megafiddle in forum C Programming
    Replies: 3
    Last Post: 06-28-2016, 10:09 PM
  2. Non null-terminated strings
    By Casey G in forum C++ Programming
    Replies: 5
    Last Post: 05-10-2011, 07:47 PM
  3. null terminated
    By TeQno in forum C Programming
    Replies: 5
    Last Post: 06-06-2003, 06:10 PM
  4. Null Terminated Arrays
    By sean in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 06-17-2002, 11:39 AM

Tags for this Thread