Thread: Creating a long, specific, c string

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    I think you mean something like this:
    Code:
    #include <stdio.h>
    #include <string.h>
     
    #define SIZE 1100
     
    #define B10   "          "
    #define B50   B10 B10 B10 B10 B10
    #define B100  B50 B50
    #define B500  B100 B100 B100 B100 B100
    #define B1000 B500 B500
     
    int main() {
        // "x" + 1098 blanks + "y"
        char s[SIZE+1] = "x" B1000 B50 B10 B10 B10 B10 "        y";
     
        printf("%zu\n", strlen(s));
     
        return 0;
    }
    But I don't see why you can't do something like this (even though it's runtime) :
    Code:
        char s[SIZE + 1] = {0};
        memset(s, ' ', SIZE);
        s[0] = 'x';
        s[SIZE - 1] = 'y';
    A little inaccuracy saves tons of explanation. - H.H. Munro

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    Quote Originally Posted by john.c View Post
    I think you mean something like this:
    Not super elegant, but it works well enough. Thanks!
    Mainframe assembler programmer by trade. C coder when I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating files in a specific directory
    By hinesro in forum C Programming
    Replies: 5
    Last Post: 02-01-2015, 01:36 AM
  2. Replies: 16
    Last Post: 08-01-2012, 12:14 AM
  3. problem creating program to the specific specification
    By rushhour in forum C++ Programming
    Replies: 22
    Last Post: 11-28-2008, 12:15 AM
  4. unsigned long long to string conversion
    By Wiretron in forum C++ Programming
    Replies: 6
    Last Post: 12-21-2007, 04:02 AM
  5. Creating files in specific directories
    By Kyoto Oshiro in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 08:50 PM

Tags for this Thread