Python Results Converted To C Struct Header File


 
Thread Tools Search this Thread
Top Forums Programming Python Results Converted To C Struct Header File
# 8  
Old 11-13-2015
Here's a simplified and easier version:
Code:
dest = open('wp.h', 'a+')

dest.write(
'''
struct {

        char *name;
        char *fixed_version;

} filename_versions[] = {

{"moses-red-sea","1.00.03"},
{"genesis-snake","2.03"},
{"deliverance","5.0.010"},
        {NULL, NULL}
};
'''
);

dest.close()

Trick here is to use the triple quotes (''' ... ''') ; ain't python cool B-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

Python DictWriter header - not writing in first line of existing file

Hello I am facing a very unique problem and not able to understand why. I have written a function which will check header of the file. If header is present good else it will write the header on top def writeHeaderOutputCSV(fileName): # See if the file exist already try: ... (0 Replies)
Discussion started by: radioactive9
0 Replies

3. Programming

How to open hidden file and converted into .dat format?

Here i am having ".tmideg0"hidden file . I have made programm but it doesnot work #!/usr/bin/perl $runDir = $ENV{"REGR_RUN_DIR"}; @files = (<*.tmideg0> <*.tmideg1>); foreach $FILE (@files) { open (IN, $FILE) || die "Couldn't open $FILE for reading"; open (OUT,... (2 Replies)
Discussion started by: avi1991nash
2 Replies

4. Programming

search file and put into struct

hi everybody, I need some help with some programming. I need to write a file that can search in a text file and read the whole line into a struct. the struct = struct Transistor { char chType; char chFabrikant; float fPrijs; enum Transistor_Behuizing { empty,TO18, TO39,... (8 Replies)
Discussion started by: metal005
8 Replies

5. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

6. Programming

Can't assign struct variable in header file

Hi guys. I have a header file including a structure like this: typedef struct { int index = -1; stack_node *head; } stack; But when compiling with cc it shows error at the assignment line (int index = -1): error: expected ‘:', ‘,', ‘;', ‘}' or ‘__attribute__' before ‘=' token... (1 Reply)
Discussion started by: majid.merkava
1 Replies

7. Programming

Python, struct.pack

Hello, I found some code on line. Is a python function that bring up an Internet interface, here the code: # Get existing device flags ifreq = struct.pack('16sh', 'wlan0', 0) flags = struct.unpack('16sh', fcntl.ioctl(sockfd, SIOCGIFFLAGS, ifreq)) I'm starting... (1 Reply)
Discussion started by: Dedalus
1 Replies

8. UNIX for Dummies Questions & Answers

How to access a struct within a struct?

Can someone tell me how to do this? Just a thought that entered my mind when learning about structs. First thought was: struct one { struct two; } struct two { three; } one->two->three would this be how you would access "three"? (1 Reply)
Discussion started by: unbelievable21
1 Replies

9. Programming

Python converted from /bin/sh shell - backup script.

Hello, I have a shell script I wrote in /bin/sh to backup my web sever. I am now on a host (someone reselling rackspace server hosting to me) and when setting up cron, it actually has a dropdown list of "command languages" that you have to choose from. my options are: ruby php perl... (0 Replies)
Discussion started by: jzacsh
0 Replies

10. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies
Login or Register to Ask a Question
STRCAT(3)						     Linux Programmer's Manual							 STRCAT(3)

NAME
strcat, strncat - concatenate two strings SYNOPSIS
#include <string.h> char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n); DESCRIPTION
The strcat() function appends the src string to the dest string, overwriting the null byte ('') at the end of dest, and then adds a ter- minating null byte. The strings may not overlap, and the dest string must have enough space for the result. The strncat() function is similar, except that * it will use at most n characters from src; and * src does not need to be null-terminated if it contains n or more characters. As with strcat(), the resulting string in dest is always null-terminated. If src contains n or more characters, strncat() writes n+1 characters to dest (n from src plus the terminating null byte). Therefore, the size of dest must be at least strlen(dest)+n+1. A simple implementation of strncat() might be: char* strncat(char *dest, const char *src, size_t n) { size_t dest_len = strlen(dest); size_t i; for (i = 0 ; i < n && src[i] != '' ; i++) dest[dest_len + i] = src[i]; dest[dest_len + i] = ''; return dest; } RETURN VALUE
The strcat() and strncat() functions return a pointer to the resulting string dest. CONFORMING TO
SVr4, 4.3BSD, C89, C99. SEE ALSO
bcopy(3), memccpy(3), memcpy(3), strcpy(3), strncpy(3), wcscat(3), wcsncat(3) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2008-06-13 STRCAT(3)