So I'm guessing I'm missing something fairly simple here but I am trying to read a file line by line, tokenizing the buffer as I go. I have pasted the basics of what I'm trying to do with my code. I have never had issue with strtok, so I'm guessing it has to do with the buffer that I'm using. Any nudges in the right direction? I read that strtok isn't a great option, but it's the only thing I'm familiar with (I suppose I could write my own function) It reads the first token as it's supposed to every time. It doesn't seg fault until I try to find the second token with "strtok(NULL," ");"  I don't know why this was downvoted as a duplicate. Yes, there are answers out there that tell the basics of what I'm trying to do, but I want to understand the problem, not just cut and paste." I'd prefer to know WHY there is a seg fault and why my code is behaving as it does. No need to downvote when I'm asking specific questions not pointed out directly in other posts.  const char *file = "path/to/file/file.txt"; void tokenize();  //Eventually file will be command line opt FILE *open_file(const char *file);  int main(int argc, char *argv[]) {     tokenize(); }  void tokenize() {     FILE *fp;     fp = open_file(file);     char buffer[BUFSIZ];      while(fgets(buffer,BUFSIZ,fp) != NULL)     {         //puts("========================================");         //puts(buffer);         //puts("========================================");          char *data = strdup(buffer);         char *token;         token = strtok(data, " ");         //puts(token);         while(token != NULL)         {             token = strtok(NULL, " ");              puts("++++++++++++++++++++++++++++++++++++++++++++++");             puts(token);             puts("++++++++++++++++++++++++++++++++++++++++++++++");         }     } fclose(fp) }  FILE *open_file(const char *file) {     FILE *fp;     fp = fopen(file, "r");      if(fp == NULL)     {         perror("Error opening file");     }     return fp; }
Java has a convenient split method:  String str = "The quick brown fox"; String[] results = str.split(" ");   Is there an easy way to do this in C++?
Suppose a book consists of three sections:     The book is/was divided into three sections.   I am thinking the past tense option "was" should be used, because the act of dividing the book into three sections happened at the time of writing. Is my analysis good? How often is the Golden Ratio actually used in modern design? The  is the stuff of legend () and is . My question is two-fold, really: Is the Golden Ratio really a good tool used in modern design (defined here as 20th century on forward), and if so, how often is it used outside of the aforementioned known uses?  EDIT: To @e100's first comment, examples of modern use of the Golden Ratio would be a great thing to add here if there any documented or arguably conclusive uses of it. Let $A$ , $B$ be topological spaces such that there for some subset $D$ of $B$ there is a homeomorphism form $A$ to $D$ and for some subset $E$ of $A$ there is a homeomorphism form $B$ to $E$ ; then must there exist a homeomorphism from $A$ to $B$ ? Determining if trees within forest gaps are clustered using R? How to do multiple lines within braces? Proving $\sum\limits_{i=1}^k | \langle x,v_i \rangle \langle y,v_i\rangle| \leq \|x\|\cdot \|y\|$ Let $V$ be a real inner product space, and let $v_1,v_2, \dots ,v_k$ be an orthonormal set of vectors. How do you prove that  $$\sum_{i=1}^k | \langle x,v_i \rangle \langle y,v_i\rangle| \leq \|x\|\cdot\|y\|?$$  When does the equality hold?  I've been trying to do this with the Bessel and Cauchy-Schwarz inequalities, but I can't make it work yet. Any help would be greatly appreciated. What to do when you find a bad link in an answer? If a link has gone stale in an answer, what is the correct way to report this in the SO universe?  e.g. Jon's first link in    I have added a comment but not found the correct link yet. Minecraft's got an "Open to LAN" feature, which can be used to set up a local server when two computers running Minecraft are on the same network. Some young relatives of mine use this to play together whenever they're in the same house, but they'd like to be able to play together from their respective residences.  A server is not optimal because it's a bit complex. I've tried using Tunngle to spoof that the computers are on the same connection to no avail.  How can I convince Minecraft's "Open to LAN" that their two separate computers are on the same network? Make tools indestructible in Minecraft How to extract the boundary of a raster image? For a specific package, can I find out why it is installed?  So, can I see or it's manually installed, or that it is installed as a dependency of another package? Or that it is installed as part of the distro? How can I move an object towards another along a straight line Show that the set of polynomials with rational coefficients is countable. Dual boot Ubuntu (14.04) with Windows 10 I have 13.04 installed from a DVD that I got on eBay but the application launcher is missing. I've tried CCSM but it won't work! echo "-e" doesn't print anything I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:  echo "-e"    doesn't print anything. I guess this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other two options) also produce empty strings.  The question is how to escape the sequence "-e" for echo to get the natural output ("-e"). Coefficients change signs I have a dataset where there is a high degree of multicollinearity, with all variables correlating positively with each other and the dependent variable. However, on some of the models I run I get a couple of significant negative coefficients. Basically there are two coefficients that depending on what variables I include in the model, I can manipulate their signs.  My understanding is that if the variance-covariance matrix only contain positive values, then all coefficients should also be positive. Is this correct? How does AdamW weight_decay works for L2 regularization? hello I have a question about weight regularization in Adam apparently the weight_decay in the AdamW function  has the same impact as an L2 regularization my questions are: is that parameter the same as lambda that we have in the regularization term?  how does it exactly work? and what is its impact on the model complexity? What is "pure energy" in matter-antimatter annihilation made of? I used to read the term "pure energy" in the context of matter-antimatter annihilation.  Is the "pure energy" spoken of photons? Is it some form of heat?  Some kind of particles with mass?   Basically, what does "pure energy" in the context of matter-antimatter annihilation refer to? What home printer would allow for exact alignment of front and back? Note: I'm not a graphic designer, but this seemed like the most relevant place to post. Feel free to send me off somewhere else if I'm not in the right place.  I would like to make some notebooks with double-sided grid paper that I've already designed, but my printer seems like it doesn't allow for absolutely exact alignment. Even if one side prints nice and straight, the other side will be slightly skewed left to right by one to two millimeters, which I read from an earlier post is a pretty reasonable variance for a home printer. So I suspect it's not possible to get both sides completely aligned on this printer – but if I'm wrong, please let me know how.  What kind of printer would allow for absolutely exact alignment? Is there any difference between inkjet and laser in this regard, or a more expensive printer versus a cheaper one?